I'm guessing matching with a reference will help:
mpl<T: Clone> Clone for Coll<T> {
fn clone (&self) -> Coll<T> {
match *self {
A(x,ref y) => A(x,y.clone()),
B(x,ref y) => B(x,y.clone())
}
}
}
(Haven't tried it though)
// Magnus Holm
On Mon, Apr 21, 2014 at 12:57 PM, Artella Coding
<[email protected]> wrote:
>
> Suppose I have the enum :
>
> enum Coll<T> {
> A(f64,T),
> B(f64,T)
> }
>
> I know that the compiler can automatically derive the Clone trait for the
> above. However I would like to manually implement it and was unsuccessful in
> my attempt. I tried the following :
>
> enum Coll<T> {
> A(f64,T),
> B(f64,T)
> }
>
> impl<T: Clone> Clone for Coll<T> {
> fn clone (&self) -> Coll<T> {
> match *self {
> A(x,y) => A(x,y.clone()),
> B(x,y) => B(x,y.clone())
> }
> }
> }
>
> but I got the error message :
>
> q.rs:9:13: 9:19 error: cannot move out of dereference of `&`-pointer
> q.rs:9 A(x,y) => A(x,y.clone()),
> ^~~~~~
> q.rs:10:13: 10:19 error: cannot move out of dereference of `&`-pointer
> q.rs:10 B(x,y) => B(x,y.clone())
> ^~~~~~
> error: aborting due to 2 previous errors
>
> What do I need to do to fix the code above? Thanks
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev