April 2026
Intermediate
631 pages
16h 20m
English
This section provides the code solutions for the practice exercises in Section 10.4. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Resolving borrowing conflicts in mutable and immutable references
fn main() { let mut some_str = String::from("I am String"); let ref1 = &some_str; println!("{ref1}"); let ref2 = &mut some_str; ref2.push_str(" additional information"); println!("{ref2}");}
Resolving lifetimes in function references
fn identity(a: &i32) -> &i32 { a}fn main() { let mut x_ref: Option<&i32> = None; { let x = 7; x_ref = Some(identity(&x)); assert_eq!(*x_ref.unwrap(), 7); }}
Correcting scope and lifetimes in option ...
Read now
Unlock full access