What does &variable
mean when it is used in patterns or closure arguments?
for &code in self.exit_code.iter() { ... }
let mut new_seps = do seps.iter().fold(~[]) |result, &next| { ... }
Here we have &code
and &next
in for
loop and closure definition. What do &
sign in these mean? Why cannot we simply use code
and next
, without the ampersand? Is it related to ref
qualifier in pattern matching? Is it related to &
in self
argument in trait implementations?
I couldn't find anything on this syntax neither in current Rust reference manual nor in tutorial. Currently I think this is some kind of implicit dereferencing (this follows from error message which appears if I omit &
in the pattern), but I'm not sure.