Alg*_*goQ 1 clone vector traits rust
如何克隆带有结构项的向量Rust。
我已经尝试过.to_vec(),但似乎我不能,因为我正在使用结构。
struct Abc {
id: u32,
name: String
}
let mut vec1: Vec<Abc> = vec![];
let item1 = Abc {
id: 1,
name: String::from("AlgoQ")
}
vec1.push(item1)
let vec2 = vec1.to_vec();
Run Code Online (Sandbox Code Playgroud)
错误:
the trait bound `blabla::Abc: Clone` is not satisfied
the trait `Clone` is not implemented for `blabla::Abc`rustc(E0277)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3877 次 |
| 最近记录: |