[英]Derive Clone for array of something that is Clone?
這段代碼( 也在玩 )
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
沒有問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.