Complete the code to create a new Box smart pointer holding the value 5.
let b = Box::[1](5);
The Box::new function creates a new Box smart pointer that owns the value inside it.
Complete the code to clone a Rc smart pointer.
let rc2 = Rc::[1](&rc1);copy which is not implemented for Rc.duplicate or replicate which do not exist.The clone method on Rc increases the reference count and returns a new pointer to the same data.
Fix the error in the code by completing the blank to get a mutable reference from a RefCell.
let mut_ref = refcell.[1]().unwrap();borrow which only gives an immutable reference.get_mut which requires exclusive ownership.The borrow_mut method on RefCell returns a mutable reference wrapped in a RefMut, which you can unwrap safely if no other borrows exist.
Fill both blanks to create a HashMap from strings to their lengths, only including words longer than 3 characters.
let lengths = words.iter().filter(|&word| word.len() [1] 3).map(|word| (word.to_string(), word.[2]())).collect::<HashMap<_, _>>();
< instead of > in the filter condition.is_empty which returns a boolean, not length.The filter keeps words with length greater than 3, and the map creates pairs of the word and its length.
Fill both blanks to create a HashMap from uppercase keys to values, including only entries with positive values.
let result = data.iter().map(|(k, v)| (k.[1](), *v)).filter(|(_, v)| *v [2] 0).collect::<HashMap<_, _>>();
to_lowercase instead of uppercase.The map converts keys to uppercase strings, the filter keeps only positive values, and the collect gathers them into a HashMap.