Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Q: why do we need to first assign a vector to a variable and use the variable
- // to do things to the vector? Why can't we do things directly to the vector?
- // See code below for examples.
- // It seems Rust was intentionally designed in this fashion because the first
- // rule of ownership is
- // "Each value in Rust has a variable that’s called its owner."
- fn main() {
- let mut v = vec![1];
- v.push(2);
- println!("{:?}", v);
- // why can't we just do one of the following?
- println!("{:?}", vec![1].push(2)); // () because ?
- println!("{:?}", (&mut vec![1]).push(2)); // () because ?
- }
Add Comment
Please, Sign In to add comment