[英]Expected concrete lifetime, found bound lifetime parameter when storing a fn in a struct
我正在嘗試將函數存儲在結構中:
trait T<'a> {}
struct A {}
struct B<'a> {
a: &'a A
}
impl<'a> T<'a> for B<'a> {}
fn f1<'a, E: T<'a>>(a: &'a A) {}
struct D {
f: fn(&A)
}
fn main() {
let d = D { f: f1::<B> };
}
編譯器抱怨:
error[E0308]: mismatched types
--> src/main.rs:18:20
|
18 | let d = D { f: f1::<B> };
| ^^^^^^^ expected concrete lifetime, found bound lifetime parameter
|
= note: expected type `fn(&A)`
= note: found type `fn(&A) {f1::<'_, B<'_>>}`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.