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