rustlings/exercises/borrowing/borrowing2.rs
James Gill b7c5165757 feat: Add exercises for understanding borrowing
Exercises to explore immutable borrowing, mutable borrowing, and "aliasing xor mutability".
2021-10-26 08:17:43 -04:00

19 lines
411 B
Rust

// borrowing2.rs
//
// Rust has strong guarantees about immutability. In order for something
// to be mutated, it must be marked explicitly. Make this compile only
// by changing the mutabilities of the calls.
// I AM NOT DONE
fn main() {
let hello = String::from("Hello ");
append_world(&hello);
assert_eq!(&hello, "Hello world!");
}
fn append_world(s: &String) {
s.push_str("world!");
}