[rust-dev] Generic enums : manually implementing Clone trait
pcwalton at mozilla.com
Mon Apr 21 08:24:33 PDT 2014
On 4/21/14 7:59 AM, José Armando García Sancio wrote:
> On a similar note, why did Rust decide to use the keyword "ref" when
> "borrowing" in those cases and the keyword "&" when borrowing in
> function arguments? Is the semantic different?
`&` in a pattern is the opposite of a reference: it *de*references in
let &x = &3;
sets `x` to 3 (not `&3`).
This is for symmetry: consider that:
let (x, y) = (1, 2);
sets `x` to 1 and `y` to 2.
Because `&` is taken to destructure references, we needed another
keyword to take a reference. Hence, `ref`.
More information about the Rust-dev