Editor's note: This code no longer produces the same error after RFC 599 was implemented, but the concepts discussed in the answers are still valid.爲什麼在框架<T>中需要「明確的生存期限」?
我試圖編譯這段代碼:
trait A {
fn f(&self);
}
struct S {
a: Box<A>,
}
,我得到這個錯誤:
a.rs:6:13: 6:14 error: explicit lifetime bound required
a.rs:6 a: Box<A>,
我想S.a
自己的A
一個實例,也不要看看這個生命在這裏是多麼適合。我需要做什麼才能使編譯器高興?
我防鏽版本:
rustc --version
rustc 0.12.0-pre-nightly (79a5448f4 2014-09-13 20:36:02 +0000)
感謝您的RFC鏈接,它確實揭示了Boxes內部的生命週期。 – 2014-09-22 03:14:45