当前位置: 代码迷 >> 综合 >> rust iterator(todo)
  详细解决方案

rust iterator(todo)

热度:43   发布时间:2024-01-05 10:22:16.0

 为什么调用count就会移动了?

use std::env;fn main() -> std::io::Result<()> {let mut param = env::args();let paramCount = param.count();println!("count ={}", paramCount);let a = param.next();println!("a = {:?}", a);
}

6   |     let mut param = env::args();|         --------- move occurs because `param` has type `Args`, which does not implement the `Copy` trait
7   | 
8   |     let paramCount = param.count();|                            ------- `param` moved due to this method call
...
11  |     let a = param.next();|             ^^^^^ value borrowed here after move|
note: this function takes ownership of the receiver `self`, which moves `param`--> /root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:203:14|
203 |     fn count(self) -> usize|              ^^^^For more information about this error, try `rustc --explain E0382`.

  相关解决方案