此代码(也在播放中)
use std::sync::Arc;
struct Foo {
x: isize, // Something complex in actual code, implements Drop
}
#[derive(Clone)]
struct Good {
a: Option<Arc<Foo>>,
b: Option<Arc<Foo>>,
c: Option<Arc<Foo>>,
}
#[derive(Clone)]
struct Bad {
x: [Option<Arc<Foo>>; 3],
}
fn main() {
println!("See?");
}
失败Bad
了
<anon>:16:5: 16:29 error: the trait `core::marker::Copy` is not implemented for the type `alloc::arc::Arc<Foo>` [E0277]
<anon>:16 x: [Option<Arc<Foo>>; 3],
^~~~~~~~~~~~~~~~~~~~~~~~
<anon>:14:10: 14:15 note: in expansion of #[derive_Clone]
但它没有问题Good
。
- 这是为什么,
- 有什么解决方法吗?我并不热衷于处理 12 个独立的字段。