Dear rust devs,

    let vec = vec![("a".to_string(), "b".to_string())];

    for &(ref a, ref b) in vec.iter() {
        println!("{}: {}", a, b);
    }

I understand that the '&' and 'ref' are needed here, because otherwise
the 'String' could be moved out of the 'Vec'.

I don't quite understand, why there's the need for these explicit refs,
why isn't the outer '&' enough to indicate that everything inside of
the pattern is also referenced?

Why isn't it possible to just have (with the same semantics):

    for &(a, b) in vec.iter() {
        println!("{}: {}", a, b);
    }


Without these refs pattern matching would be aesthetically more in sync
with the types, which I would consider very pleasing. 


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

Reply via email to