Back to questions
JuniorTheoryCommon
What does the program print?
fn main() {
let a = 5;
let b = a;
println!("{a} {b}");
}5 5
- Expecting a compile error, as with a
String:i32implementsCopy, solet b = a;duplicates the value andastays usable. - Expecting
0 5: copying readsaand leaves it untouched, so both variables hold5.
- Which other types behave like
i32here, and which behave likeString? - What would happen if
aheldString::from("5")instead of5?