我们来看下 Rust 中”Sized“的使用,这是一个 Trait,路径在:std::marker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#[derive(Debug)]
struct Bar<T: ?Sized>(T);

fn main() {
let a = Bar(123);
let b = Bar(["Hello", "World"]);
let c = Bar([12.1, 22.5, 65.4]);

println!("a: {}", a.0);
for i in b.0.iter() {
println!("{}", i);
}

for i in c.0.iter() {
println!("{}", i);
}
}