3 ms·
> Safely borrowing things by reference is one of Rust's headline features Sure, but it's worth noting that references in Rust do not exist merely to avoid pass
by kibwen 4y ago
> Safely borrowing things by reference is one of Rust's headline features
Sure, but it's worth noting that references in Rust do not exist merely to avoid passing by-value. They also exist to make it easier to deal with Rust's ownership semantics: they let you pass things to a function without also requiring the function to "pass back" those things as returned values. In other words, references let you do `fn foo(x: &Bar)` rather than `fn foo(x: Bar) -> Bar`. This is a unique and interesting consequence of languages with by-default move semantics.