zoukankan      html  css  js  c++  java
  • candidate #1: `std::clone::Clone`

    struct Rec {
    width : u32,
    length : u32
    }
    fn process(rec1: Rec) -> Rec {
            let mut rec2 = rec1;
            rec2.width = 10;
        rec2.length = 11;
            rec2
    }
    fn main() {
                    let rec = Rec{width : 4, length : 16};
                    // rec.width = 100;
                    // rec.length = 10;
                     println!("{},{}", rec.width, rec.length);
                     let mut rec2 =rec.clone();
                     rec2.width = 100;
                     rec2.length = 10;
                     println!("{},{}", rec2.width, rec2.length);
                     let rec3 = process(rec);
                     println!("{},{}", rec3.width, rec3.length);
    }
    [root@bogon clone]# cargo build
       Compiling own v0.1.0 (/data2/rust/clone)
    error[E0599]: no method named `clone` found for struct `Rec` in the current scope
       --> src/main.rs:16:22
        |
    1   | struct Rec {
        | ---------- method `clone` not found for this
    ...
    16  |          let mut rec2 =rec.clone();
        |                            ^^^^^ method not found in `Rec`
        |
        = help: items from traits can only be used if the trait is implemented and in scope
        = note: the following trait defines an item `clone`, perhaps you need to implement it:
                candidate #1: `std::clone::Clone`
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0599`.
    error: could not compile `own`.
    
    To learn more, run the command again with --verbose
  • 相关阅读:
    xml文档格式学习笔记
    Visual Studio学习记录
    Java学习笔记
    C#项目学习记录
    Linux命令行与shell脚本编程大全 学习笔记
    NodeJS (npm) 学习笔记
    Angular学习笔记
    TypeScript学习笔记
    java 项目相关 学习记录
    docker学习记录
  • 原文地址:https://www.cnblogs.com/dream397/p/14194735.html
Copyright © 2011-2022 走看看