A. Error: cannot move `node` into `Some` because `node` does not implement Copy; fix by wrapping node in Box::new()
B. Error: missing semicolon after node declaration; fix by adding semicolon
C. Error: left field must be a reference; fix by using &node
D. No error; code compiles successfully
Solution
Step 1: Identify the error cause
left field expects Option, but Some(node) tries to move Node directly, causing type mismatch.
Step 2: Fix by boxing node
Wrap node in Box::new(node) inside Some to match Option type.
Final Answer:
Error: cannot move `node` into `Some` because `node` does not implement Copy; fix by wrapping node in Box::new() -> Option A
Quick Check:
Box node before Some to fix type error [OK]
Hint: Wrap node in Box::new() for Option [OK]
Common Mistakes:
Trying to use node directly without Box
Using references without lifetimes
Ignoring compiler type mismatch errors
5. You want to manually create a binary tree in Rust with root value 10, left child 5, and right child 15. Which code snippet correctly builds this tree and prints the right child's value?
hard
A. fn main() {
struct Node {
value: i32,
left: Option,
right: Option,
}
let left = Node { value: 5, left: None, right: None };
let right = Node { value: 15, left: None, right: None };
let root = Node {
value: 10,
left: Some(left),
right: Some(right),
};
println!("{}", root.right.as_ref().unwrap().value);
}