[back]
Rust Example Of Required Two Lifetime Specifiers
modified: 2015-03-22 04:22:15

    struct Data<'a, 'b> {
        a: &'a uint, b: &'b uint,
    }

    struct Duhta<'a> {
        a: &'a uint, b: &'a uint,
    }

    fn main() {
        let a = 1u;
        /*
        let a1 = {
            let b = 2u;
            let x = Data{a: &a, b: &b};
            x.a
        };
        println!("{}", a1);
        */
    
        // won't compile, Duhta loses type info
        let a2 = {
            let b = 2u;
            let x = Duhta{a: &a, b: &b};
            x.a
        };
        println!("{}", a2);
    
    }