Cool thanks. I had skimmed through the sections you cited, but the problem
was that in my version I was trying to clone by creating a new copy of x as
follows :
impl<'a,T: Clone> Clone for Cls<'a,T> {
fn clone(&self) -> Cls<'a, T> {
Cls{ x: & (*self.x).clone() }
}
}
and I was getting the error message :
test1.rs:8:17: 8:36 error: borrowed value does not live long enough
test1.rs:8 Cls{ x: & (*self.x).clone() }
Your solution solves my problem. Thanks.
On Mon, Apr 21, 2014 at 5:13 PM, Alex Crichton <[email protected]> wrote:
> > How do I manually implement "clone()" for Structs/Enums with lifetime
> > parameters (e.g. for struct below)?
> >
> > ---------------------------------------------------
> > struct Cls<'a,T> {
> > x:&'a T
> > }
>
> impl<'a, T: Clone> Clone for Cls<'a, T> {
> fn clone(&self) -> Cls<'a, T> {
> Cls { x: self.x }
> }
> }
>
> You may find the generics [1] and traits [2] sections of the tutorial
> helpful as well!
>
> [1] - http://static.rust-lang.org/doc/master/tutorial.html#generics
> [2] - http://static.rust-lang.org/doc/master/tutorial.html#traits
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev