let s1 = String::from("hi there"); let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work println!("s1 = {}, s2 = {}", s1, s2); } output: s1 = hi there, s2 = hi there fn main() { let s1 = String::from("hi there"); let s2 = s1; // if had let s2 = s1; instead, next line would not work println!("s1 = {}, s2 = {}", s1, s2); } output: error[E0382]: borrow of moved value: `s1` --> src/main.rs:4:30 | 2 | let s1 = String::from("hi there"); | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 3 | let s2 = s1; // if had let s2 = s1; instead, next line would not work | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after moveFor more information about this error, try rustc−−expla∈E0382. error: could not compile playground due to previous error
fn main(){ let s1 = String::from("hi there"); let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work println!("s1 = {}, s2 = {}", s1, s2); }Output
s1 = hi there, s2 = hi there
fn main(){ let s1 = String::from("hi there"); //let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); }Output
error[E0382]: borrow of moved value: `s1` --> inClass.rs:5:34 | 2 | let s1 = String::from("hi there"); | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 3 | //let s2 = s1.clone(); // if had let s2 = s1; instead, next line would not work 4 | let s2 = s1; | -- value moved here 5 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move
error: aborting due to previous error
For more information about this error, try `rustc --explain E0382`.
Original Program: fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); } Output: s1 = hi there, s2 = hi there Modified Program: fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); } Output: error[E0382]: borrow of moved value: `s1` --> src/main.rs:4:31 | 2 | let s1 = String::from("hi there"); | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 3 | let s2 = s1; | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move error: aborting due to previous error For more information about this error, try `rustc --explain E0382`.(Edited: 2021-10-06)
Program 1: fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2);}
Program 2: fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2);} (Edited: 2021-10-06)
fn main() { let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2); }
output : s1 = hi there, s2 = hi there
fn main() { let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2); }
output :
error[E0382]: borrow of moved value: `s1` --> example.rs:4:31 | 2 | let s1 = String::from("hi there"); | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 3 | let s2 = s1; | -- value moved here 4 | println!("s1 = {}, s2 = {}", s1, s2); | ^^ value borrowed here after move
error: aborting due to previous error(Edited: 2021-10-06)
let s1 = String::from("hi there"); let s2 = s1.clone(); println!("s1 = {}, s2 = {}", s1, s2);}
Output:
Modified Program: fn main() {
let s1 = String::from("hi there"); let s2 = s1; println!("s1 = {}, s2 = {}", s1, s2);}
Output:
--> main.rs:4:31 |2 | let s1 = String::from("hi there");
| -- move occurs because `s1` has type `std::string::String`, which does not implement the `Copy` trait3 | let s2 = s1; // if had let s2 = s1; instead, next line w...
| -- value moved here4 | println!("s1 = {}, s2 = {}", s1, s2);
| ^^ value borrowed here after move