File tree Expand file tree Collapse file tree 1 file changed +1
-1
lines changed Expand file tree Collapse file tree 1 file changed +1
-1
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ println!("1 new tweet: {}", tweet.summarize());
85
85
86
86
这会打印出 ` 1 new tweet: horse_ebooks: of course, as you probably already know, people ` 。
87
87
88
- 注意因为示例 10-13 中我们在相同的 * lib.rs* 里定义了 ` Summary ` trait 和 ` NewsArticle ` 与 ` Tweet ` 类型,所以他们是位于同一作用域的。如果这个 * lib.rs* 是对应 ` aggregator ` crate 的,而别人想要利用我们 crate 的功能为其自己的库作用域中的结构体实现 ` Summary ` trait。首先他们需要将 trait 引入作用域。这可以通过指定 ` use aggregator::Summary; ` 实现,这样就可以为其类型实现 ` Summary ` trait 了。` Summary ` 还必须是公有 trait 使得其他 crate 可以实现它,这也是为什么实例 10-12 中将 ` pub ` 置于 ` trait ` 之前。
88
+ 注意因为示例 10-13 中我们在相同的 * lib.rs* 里定义了 ` Summary ` trait 和 ` NewsArticle ` 与 ` Tweet ` 类型,所以他们是位于同一作用域的。如果这个 * lib.rs* 是对应 ` aggregator ` crate 的,而别人想要利用我们 crate 的功能为其自己的库作用域中的结构体实现 ` Summary ` trait。首先他们需要将 trait 引入作用域。这可以通过指定 ` use aggregator::Summary; ` 实现,这样就可以为其类型实现 ` Summary ` trait 了。` Summary ` 还必须是公有 trait 使得其他 crate 可以实现它,这也是为什么示例 10-12 中将 ` pub ` 置于 ` trait ` 之前。
89
89
90
90
实现 trait 时需要注意的一个限制是,只有当 trait 或者要实现 trait 的类型位于 crate 的本地作用域时,才能为该类型实现 trait。例如,可以为 ` aggregator ` crate 的自定义类型 ` Tweet ` 实现如标准库中的 ` Display ` trait,这是因为 ` Tweet ` 类型位于 ` aggregator ` crate 本地的作用域中。类似地,也可以在 ` aggregator ` crate 中为 ` Vec<T> ` 实现 ` Summary ` ,这是因为 ` Summary ` trait 位于 ` aggregator ` crate 本地作用域中。
91
91
You can’t perform that action at this time.
0 commit comments