diff --git a/src/basic/collections/hashmap.md b/src/basic/collections/hashmap.md index 3aace70f..499a3548 100644 --- a/src/basic/collections/hashmap.md +++ b/src/basic/collections/hashmap.md @@ -300,3 +300,8 @@ assert_eq!(hash.get(&42), Some(&"the answer")); > 目前,`HashMap` 使用的哈希函数是 `SipHash`,它的性能不是很高,但是安全性很高。`SipHash` 在中等大小的 `Key` 上,性能相当不错,但是对于小型的 `Key` (例如整数)或者大型 `Key` (例如字符串)来说,性能还是不够好。若你需要极致性能,例如实现算法,可以考虑这个库:[ahash](https://github.com/tkaitchuck/ahash) 最后,如果你想要了解 `HashMap` 更多的用法,请参见本书的标准库解析章节:[HashMap 常用方法](../../std/hashmap.md) + + +## 课后练习 + +> [Rust By Practice](https://zh.practice.rs/collections/hashmap.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice)。 \ No newline at end of file diff --git a/src/basic/collections/vector.md b/src/basic/collections/vector.md index a1090c0c..71b68e0e 100644 --- a/src/basic/collections/vector.md +++ b/src/basic/collections/vector.md @@ -232,3 +232,8 @@ fn main() { 在实际使用场景中,特征对象数组要比枚举数组常见很多,主要原因在于[特征对象](../trait/trait-object.md)非常灵活,而编译器对枚举的限制较多,且无法动态增加类型。 最后,如果你想要了解 `Vector` 更多的用法,请参见本书的标准库解析章节:[`Vector`常用方法](../../std/vector.md) + + +## 课后练习 + +> [Rust By Practice](https://zh.practice.rs/collections/vector.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice)。 \ No newline at end of file diff --git a/src/basic/compound-type/string-slice.md b/src/basic/compound-type/string-slice.md index 8bf44f97..6fcd009e 100644 --- a/src/basic/compound-type/string-slice.md +++ b/src/basic/compound-type/string-slice.md @@ -430,3 +430,4 @@ for b in "中国人".bytes() { > Rust By Practice,支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice)。 > - [字符串](https://zh.practice.rs/compound-types/string.html) > - [切片](https://zh.practice.rs/compound-types/slice.html) +> - [String](https://zh.practice.rs/collections/String.html) \ No newline at end of file diff --git a/src/basic/trait/advance-trait.md b/src/basic/trait/advance-trait.md index 03435f63..085723f4 100644 --- a/src/basic/trait/advance-trait.md +++ b/src/basic/trait/advance-trait.md @@ -418,3 +418,8 @@ fn main() { 当然,解决办法还是有的,要不怎么说 Rust 是极其强大灵活的编程语言!Rust 提供了一个特征叫 [`Deref`](https://course.rs/advance/smart-pointer/deref.html),实现该特征后,可以自动做一层类似类型转换的操作,可以将 `Wrapper` 变成 `Vec` 来使用。这样就会像直接使用数组那样去使用 `Wrapper`,而无需为每一个操作都添加上 `self.0`。 同时,如果不想 `Wrapper` 暴漏底层数组的所有方法,我们还可以为 `Wrapper` 去重载这些方法,实现隐藏的目的。 + + +## 课后练习 + +> [Rust By Practice](https://zh.practice.rs/generics-traits/advanced-traits.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice)。 \ No newline at end of file diff --git a/src/basic/trait/trait-object.md b/src/basic/trait/trait-object.md index 1307a6da..7fff2378 100644 --- a/src/basic/trait/trait-object.md +++ b/src/basic/trait/trait-object.md @@ -357,3 +357,8 @@ error[E0038]: the trait `std::clone::Clone` cannot be made into an object ``` 这意味着不能以这种方式使用此特征作为特征对象。 + + +## 课后练习 + +> [Rust By Practice](https://zh.practice.rs/generics-traits/trait-object.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice)。 \ No newline at end of file diff --git a/src/basic/trait/trait.md b/src/basic/trait/trait.md index c7ece8f7..c45ef721 100644 --- a/src/basic/trait/trait.md +++ b/src/basic/trait/trait.md @@ -576,3 +576,8 @@ fn main() { 以上两个例子较为复杂,目的是为读者展示下真实的使用场景长什么样,因此需要读者细细阅读,最终消化这些知识对于你的 Rust 之路会有莫大的帮助。 最后,特征和特征约束,是 Rust 中极其重要的概念,如果你还是没搞懂,强烈建议回头再看一遍,或者寻找相关的资料进行补充学习。如果已经觉得掌握了,那么就可以进入下一节的学习。 + + +## 课后练习 + +> [Rust By Practice](https://zh.practice.rs/generics-traits/traits.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice)。 \ No newline at end of file