面试题答案
一键面试// 定义特征
trait Container {
type Item;
fn get_item(&self) -> &Self::Item;
}
// 定义结构体
struct MyBox<T>(T);
// 为MyBox实现Container特征
impl<T> Container for MyBox<T> {
type Item = T;
fn get_item(&self) -> &Self::Item {
&self.0
}
}