跳至主要內容

08-借用

黑静美原创...小于 1 分钟编程rust

摘编自学校课件

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);

}
上次编辑于:
贡献者: Heijingmei
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v3.1.3