I want to add function like _1(), _2(), etc for Rust tuple. Unfortunately I
do not understand how to tell compiler lifetime of returning result in case
of `trait`

pub trait TupleVal<T> {
    pub pure fn _1() -> T;
    pub pure fn _2() -> T;
}

impl <T>(T, T): TupleVal<T> {
    pure fn _1() -> T {
        let (a, _) = self;
        a
    }
    pure fn _2() -> T {
        let (_, b) = self;
        b
    }
}

And the errors:

test.rs:31:21: 31:25 error: moving out of self reference
test.rs:31         let (a, _) = self;
                                  ^~~~
test.rs:35:21: 35:25 error: moving out of self reference
test.rs:35         let (_, b) = self;
                                  ^~~~
error: aborting due to 2 previous errors

How can I tell the compiler returning values lifetime? Actually it couldn't
be more than lifetime of self.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to