• value used here after move


    [root@bogon fnmut]# cat src/main.rs 
    #[derive(Debug)]
    struct f_closure{
            name: String,
    }
    impl f_closure{
            fn fn_call( self) -> String{
                            self.name
            }
    }
    fn get_string<T>(name: String , mut f: T) -> String where T : FnMut(String) -> String{
                    f(name)
            }
    fn main() {
                            let mut name = String::from("kobe");
                            let  f1= |x : String | -> String {
                        name.push_str("24");
                            format!("{}+ {}",x, name)
            };
        let name2 = String::from("dirk");
            println!("name2 {}",get_string(name2, f1));
        let name3 = String::from("lakers ");
            println!("name2 {}",get_string(name3, f1));
    
    }
    [root@bogon fnmut]# cargo build
       Compiling own v0.1.0 (/data2/rust/fnmut)
    warning: type `f_closure` should have an upper camel case name
     --> src/main.rs:2:8
      |
    2 | struct f_closure{
      |        ^^^^^^^^^ help: convert the identifier to upper camel case: `FClosure`
      |
      = note: `#[warn(non_camel_case_types)]` on by default
    
    error[E0382]: use of moved value: `f1`
      --> src/main.rs:22:40
       |
    20 |     println!("name2 {}",get_string(name2, f1));
       |                                           -- value moved here
    21 |     let name3 = String::from("lakers ");
    22 |     println!("name2 {}",get_string(name3, f1));
       |                                           ^^ value used here after move
       |
    note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `name` out of its environment
      --> src/main.rs:16:7
       |
    16 |             name.push_str("24");
       |             ^^^^
    
    error: aborting due to previous error; 1 warning emitted
    
    For more information about this error, try `rustc --explain E0382`.
    error: could not compile `own`.
    
    To learn more, run the command again with --verbose.
    cat src/main.rs 
    #[derive(Debug)]
    struct f_closure{
            name: String,
    }
    impl f_closure{
            fn fn_call( self) -> String{
                            self.name
            }
    }
    fn get_string<T>(name: String , mut f: T) -> String where T : FnMut(String) -> String{
                    f(name)
            }
    fn main() {
                            let mut name = String::from("kobe");
                            let  f1= |x : String | -> String {
                        name.push_str("24");
                            format!("{}+ {}",x, name)
            };
        let name2 = String::from("dirk");
            println!("name2 {}",get_string(name2, f1));
        //let name3 = String::from("lakers ");
            //println!("name2 {}",get_string(name3, f1));
    
    }
  • 相关阅读:
    TCP/IP的基本概念知识
    Mysql查询今天、昨天、7天、近30天、本月、上一月数据
    PHP OOP面向对象部分方法归总(代码实例子)
    PHP 变量
    PHP超级全局变量、魔术变量和魔术函数
    PHP编程效率的20个要点
    MemCache超详细解读
    CodeForces 652E Pursuit For Artifacts 边双连通分量
    HDU 2460 Network 边双连通分量 缩点
    HDU 3594 Cactus 有向仙人掌图判定
  • 原文地址:https://www.cnblogs.com/dream397/p/14192051.html
Copyright © 2020-2023  润新知