On 11/22/2013 07:01 AM, Tommi wrote:
Now, off-topic: I've been trying to post the following question to this mailing 
list for like 4 times, but no dice. I seem to have better luck when replying to 
posts, so here it goes:

struct Value {
     n: int
}

impl Value {
     fn squared(mut self) -> Value {
         self.n *= self.n;
         self
     }
}

fn main() {
     let x = Value{ n: 3 };
     let y = x.squared();
     println!("{} {}", x.n, y.n); // prints 9 9
}

self isn't being passed by value to squared, since x.n gets mutated as well. 
This must be a bug, right?

That is not what I'd expect, in any case!
;-)

PS: cannot run the code, get:

_.rs:12:16: 12:19 error: found `self` in ident position
_.rs:12     fn squared (mut self) -> Value {
                        ^~~

??? (also, underlining looks wrong; unless the actual error is about mut?)

Denis
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to