|
|
|
|
|
by haberman
2584 days ago
|
|
Coming from C++, this always throws me a bit: if (0..=10).contains(&5) {
I assume we are taking a ref to "5" (and not passing by value) because "Range" is a generic type that might be too big to want to copy (or it may not be copyable at all). But taking a reference to a number for a simple operation like this feels... weird. It makes me worry that Rust is going to be passing around pointers to some stack-allocated "5", but I hope that Rust is actually much smarter than that? |
|
Instead, this is a borrow which indicates that the callee will not mutate the argument. It makes more sense in this context.