Facts That I Know:
Normally, the non-copy types like String, Vec, etc. have the concept of ownership being moved, when it is passed as a parameter to the functions/methods, or just assigned normally to other variables.
My Questions :
- Why is it so that when I pass the similar non-copy types to println! or similar macros, it does not move the ownership of that variable, and we can use them even after println! statements ??
fn main() {
let str: String = String::from("hello, world");
println!("String: \"{}\"", str);
println!("\nThis print also works, even when the str has been passed to println! before:\nString: \"{}\"", str);
}
- Is this behavior also prevalent in other std library macros like write!, or format! ??
Please note that I have just begun learning Rust, so mind me if I have asked silly question out of curiousity, and I would be really grateful if I get help on this doubt..
Thank you in advance for your time and efforts in solving my queries..