mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 05:09:19 +00:00
Exercises to explore immutable borrowing, mutable borrowing, and "aliasing xor mutability".
19 lines
401 B
Rust
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!");
|
|
}
|