Hi,

is there a way to write something as follow in rust?

class matrix {
...
    float&   Get(int r, int c)    { return this.data[r + c*4]; }
}

matrix m;
m.Get(0, 1) = 42.;


in trust, my struct matrix would have a method called Get, but what would
it return?

struct Mat {
    data:[float, ..16]
}

impl Mat  {
    pub fn Get(&mut self, r:int, c:int) -> &mut float {
        &self.data[r+c*4]
    }
}


I get error messages about lifetime or about mutability

est.rs:107:8: 107:24 error: mismatched types: expected `&mut float` but
found `&float` (values differ in mutability)
test.rs:107         &self.data[r*4+c]
                    ^~~~~~~~~~~~~~~~


cheers,

Remi
-- 
Rémi Fontan : [email protected]
mobile: +64 21 855 351
93 Otaki Street, Miramar 6022
Wellington, New Zealand
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to