我有以下代码:
use std::collections::HashMap;
trait T: Sized {}
struct A;
impl T for A {}
fn main() {
let h: HashMap<String, T>;
}
但编译器抱怨:
error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
--> src\main.rs:10:12
|
10 | let h: HashMap<String, T>;
| ^^^^^^^^^^^^^^^^^^ `T` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `T`
= note: required by `std::collections::HashMap`
error[E0038]: the trait `T` cannot be made into an object
--> src\main.rs:10:12
|
10 | let h: HashMap<String, T>;
| ^^^^^^^^^^^^^^^^^^ the trait `T` cannot be made into an object
|
= note: the trait cannot require that `Self : Sized`
我不理解错误信息,因为我已经标记了我的特质
T
像
Sized
. 我错过什么了吗?