08-借用
原创...小于 1 分钟
摘编自学校课件
fn main(){
let i=42;
// let j= i; /* The Ownership changed, i can not be used
let j= i+1-1; //i is still uesfull
println!("{}", i);
println!("{}", j);
let s = String::from("hello");
let b =s.clone()+" world";
println!("{}", s);
println!("{}", b);
let b =s+" world"; //s cannot be used anymore
// println!("{}", s);
// ^ value borrowed here after move
println!("{}", b);
}
Powered by Waline v3.1.3