rustlings/exercises/borrowing/borrowing3.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
401 B
Rust

// borrowing3.rs
//
// A core safety feature of Rust is that it may not have mutable and immutable
// borrows. Make this compile only by changing the order of the lines.
// I AM NOT DONE
fn main() {
let mut hello = String::from("Hello ");
let hello_ref = &hello;
append_world(&mut hello);
println!("{}", hello_ref);
}
fn append_world(s: &mut String) {
s.push_str("world!");
}