【发布时间】:2019-06-07 15:26:12
【问题描述】:
这是我的结构:
#[derive(Copy, Clone)]
pub struct ArimaModel {
p: u8,
d: u8,
q: u8,
holdout_length: u16,
max_ar_lag: u8,
max_ma_lag: u8,
df_lags: u8,
time_series: Vec<f64>,
ar_lags: Vec<usize>,
}
我正在尝试将我的结构传递给多个函数。
这是我的错误:
error[E0204]: the trait `Copy` may not be implemented for this type
--> src/lib.rs:1:10
|
1 | #[derive(Copy, Clone)]
| ^^^^
...
10 | time_series: Vec<f64>,
| --------------------- this field does not implement `Copy`
11 | ar_lags: Vec<usize>,
| ------------------- this field does not implement `Copy`
【问题讨论】:
-
Vec没有实现Copy。因此,您必须使用数组或传递引用。 -
“我正在尝试将我的结构传递给多个函数” — 请您在执行该操作的位置发布代码。
-
我通过搜索 [how to implement copy for a type [rust]](stackoverflow.com/…) 找到了链接的问题。
String是这样的,因为它包含一个Vec,所以答案也同样适用。
标签: struct rust move-semantics pass-by-value