comprehensive-rust
comprehensive-rust copied to clipboard
Details in variables.md is a bit confusing
In the second item of Details in variables.md, it says :
Note that since println! is a macro, x is not moved, even using the function like syntax of println!("x: {}", x)
But it's not 100% true because variable x in the example code is i32 type which will never get moved by calling both pure function or macro.
I think either sample code or description should be changed somehow.
Please check the code below
xnever get moved somy_print()can be called multiple times without error.
fn my_print(x: i32) {
println!("Hello {}", x);
}
fn main() {
let x: i32 = 10;
my_print(x);
my_print(x);
}
The statement is true -- the x in the chapter is neither moved nor copied. But, you're correct that it is not a great way to illustrate the point. Perhaps this would be better:
fn main() {
let s = String::from("abc");
println!("{}", s);
println!("{}", s);
}
Honestly, at this point in the course, we haven't talked about moving at all, so the speaker notes could probably be simplified.