feat: renname practice.rs to zh-practice.course.rs

pull/1365/head
sunfei 8 months ago
parent 2815f01330
commit 3e08656b95

@ -303,7 +303,7 @@ where
} }
``` ```
上面的缓存有一个很大的问题:只支持 `u32` 类型的值,若我们想要缓存 `&str` 类型,显然就行不通了,因此需要将 `u32` 替换成泛型 `E`,该练习就留给读者自己完成,具体代码可以参考[这里](https://practice.rs/functional-programing/closure.html#closure-in-structs) 上面的缓存有一个很大的问题:只支持 `u32` 类型的值,若我们想要缓存 `&str` 类型,显然就行不通了,因此需要将 `u32` 替换成泛型 `E`,该练习就留给读者自己完成,具体代码可以参考[这里](https://zh-practice.course.rs/functional-programing/closure.html#closure-in-structs)
## 捕获作用域中的值 ## 捕获作用域中的值
@ -812,4 +812,4 @@ fn factory(x:i32) -> Box<dyn Fn(i32) -> i32> {
## 课后习题 ## 课后习题
> [Rust By Practice](https://practice.rs/functional-programing/closure.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/functional-programing/closure.md)。 > [Rust By Practice](https://zh-practice.course.rs/functional-programing/closure.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/functional-programing/closure.md)。

@ -324,9 +324,9 @@ unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>) -> &'b mut R
## 课后练习 ## 课后练习
> Rust By Practice支持代码在线编辑和运行并提供详细的习题解答。 > Rust By Practice支持代码在线编辑和运行并提供详细的习题解答。
> - [as](https://zh.practice.rs/type-conversions/as.html) > - [as](https://zh-practice.course.rs/type-conversions/as.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/as.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/as.md)
> - [From/Into](https://zh.practice.rs/type-conversions/from-into.html) > - [From/Into](https://zh-practice.course.rs/type-conversions/from-into.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/from-into.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/from-into.md)
> - [其它转换](https://zh.practice.rs/type-conversions/others.html) > - [其它转换](https://zh-practice.course.rs/type-conversions/others.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/others.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/others.md)

@ -186,7 +186,7 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/lifetime/static.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答) > [Rust By Practice](https://zh-practice.course.rs/lifetime/static.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答)
## 总结 ## 总结

@ -72,5 +72,5 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/basic-types/char-bool-unit.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/char-bool.md)。 > [Rust By Practice](https://zh-practice.course.rs/basic-types/char-bool-unit.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/char-bool.md)。

@ -192,4 +192,4 @@ fn forever() -> ! {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/basic-types/functions.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/functions.md)。 > [Rust By Practice](https://zh-practice.course.rs/basic-types/functions.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/functions.md)。

@ -246,7 +246,7 @@ fn main() {
Rust的位运算基本上和其他语言一样 Rust的位运算基本上和其他语言一样
| 运算符 | 说明 | | 运算符 | 说明 |
| ------- | -------------------------------------- | | ------- | ------------------------------------------------------ |
| & 位与 | 相同位置均为1时则为1否则为0 | | & 位与 | 相同位置均为1时则为1否则为0 |
| \| 位或 | 相同位置只要有1时则为1否则为0 | | \| 位或 | 相同位置只要有1时则为1否则为0 |
| ^ 异或 | 相同位置不相同则为1相同则为0 | | ^ 异或 | 相同位置不相同则为1相同则为0 |
@ -356,7 +356,7 @@ use num::complex::Complex;
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/basic-types/numbers.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/numbers.md)。 > [Rust By Practice](https://zh-practice.course.rs/basic-types/numbers.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/numbers.md)。

@ -113,5 +113,5 @@ fn ret_unit_type() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/basic-types/statements-expressions.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/statements.md)。 > [Rust By Practice](https://zh-practice.course.rs/basic-types/statements-expressions.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/basic-types/statements.md)。

@ -314,4 +314,4 @@ assert_eq!(hash.get(&42), Some(&"the answer"));
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/collections/hashmap.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/collections/Hashmap.md)。 > [Rust By Practice](https://zh-practice.course.rs/collections/hashmap.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/collections/Hashmap.md)。

@ -452,4 +452,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/collections/vector.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/collections/Vector.md)。 > [Rust By Practice](https://zh-practice.course.rs/collections/vector.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/collections/Vector.md)。

@ -472,4 +472,4 @@ Green
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/comments-docs.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答) > [Rust By Practice](https://zh-practice.course.rs/comments-docs.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答)

@ -216,4 +216,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/compound-types/array.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/array.md)。 > [Rust By Practice](https://zh-practice.course.rs/compound-types/array.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/array.md)。

@ -292,4 +292,4 @@ let none = plus_one(None);
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/compound-types/enum.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/enum.md)。 > [Rust By Practice](https://zh-practice.course.rs/compound-types/enum.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/enum.md)。

@ -713,11 +713,11 @@ for b in "中国人".bytes() {
## 课后练习 ## 课后练习
> Rust By Practice支持代码在线编辑和运行并提供详细的习题解答。 > Rust By Practice支持代码在线编辑和运行并提供详细的习题解答。
> - [字符串](https://zh.practice.rs/compound-types/string.html) > - [字符串](https://zh-practice.course.rs/compound-types/string.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/string.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/string.md)
> - [切片](https://zh.practice.rs/compound-types/slice.html) > - [切片](https://zh-practice.course.rs/compound-types/slice.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/slice.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/slice.md)
> - [String](https://zh.practice.rs/collections/String.html) > - [String](https://zh-practice.course.rs/collections/String.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/collections/String.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/collections/String.md)
<hr /> <hr />

@ -426,5 +426,5 @@ $ cargo run
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/compound-types/struct.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/struct.md)。 > [Rust By Practice](https://zh-practice.course.rs/compound-types/struct.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/struct.md)。

@ -76,4 +76,4 @@ fn calculate_length(s: String) -> (String, usize) {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/compound-types/tuple.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/tuple.md)。 > [Rust By Practice](https://zh-practice.course.rs/compound-types/tuple.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/compound-types/tuple.md)。

@ -111,4 +111,4 @@ error: a bin target must be available for `cargo run`
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/crate-module/crate.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/crate-module/crate.md)。 > [Rust By Practice](https://zh-practice.course.rs/crate-module/crate.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/crate-module/crate.md)。

@ -360,4 +360,4 @@ pub mod hosting;
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/crate-module/module.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/crate-module/module.md)。 > [Rust By Practice](https://zh-practice.course.rs/crate-module/module.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/crate-module/module.md)。

@ -468,4 +468,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/crate-module/use-pub.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/crate-module/use-pub.md)。 > [Rust By Practice](https://zh-practice.course.rs/crate-module/use-pub.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/crate-module/use-pub.md)。

@ -370,4 +370,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/flow-control.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/flow-control.md)。 > [Rust By Practice](https://zh-practice.course.rs/flow-control.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/flow-control.md)。

@ -462,7 +462,7 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/formatted-output.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答) > [Rust By Practice](https://zh-practice.course.rs/formatted-output.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答)
## 总结 ## 总结

@ -649,7 +649,7 @@ where
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/lifetime/basic.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答) > [Rust By Practice](https://zh-practice.course.rs/lifetime/basic.html),支持代码在线编辑和运行,并提供详细的习题解答。(本节暂无习题解答)
## 总结 ## 总结

@ -644,4 +644,4 @@ num @ (1 | 2)
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/pattern-match/patterns.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/pattern-match/patterns.md)。 > [Rust By Practice](https://zh-practice.course.rs/pattern-match/patterns.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/pattern-match/patterns.md)。

@ -397,4 +397,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/pattern-match/match-iflet.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/pattern-match/match.md)。 > [Rust By Practice](https://zh-practice.course.rs/pattern-match/match-iflet.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/pattern-match/match.md)。

@ -279,4 +279,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/method.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/method.md)。 > [Rust By Practice](https://zh-practice.course.rs/method.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/method.md)。

@ -312,4 +312,4 @@ fn no_dangle() -> String {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/ownership/borrowing.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/ownership/borrowing.md)。 > [Rust By Practice](https://zh-practice.course.rs/ownership/borrowing.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/ownership/borrowing.md)。

@ -338,5 +338,5 @@ fn takes_and_gives_back(a_string: String) -> String { // a_string 进入作用
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/ownership/ownership.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/ownership/ownership.md)。 > [Rust By Practice](https://zh-practice.course.rs/ownership/ownership.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/ownership/ownership.md)。

@ -214,4 +214,4 @@ let home: IpAddr = "127.0.0.1".parse().unwrap();
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/result-panic/panic.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/result-panic/panic.md)。 > [Rust By Practice](https://zh-practice.course.rs/result-panic/panic.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/result-panic/panic.md)。

@ -403,4 +403,4 @@ let x = try!(function_with_error());
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/result-panic/result.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/result-panic/result.md)。 > [Rust By Practice](https://zh-practice.course.rs/result-panic/result.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/result-panic/result.md)。

@ -427,4 +427,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/generics-traits/advanced-traits.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/advanced-trait.md)。 > [Rust By Practice](https://zh-practice.course.rs/generics-traits/advanced-traits.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/advanced-trait.md)。

@ -467,7 +467,7 @@ fn main() {
## 课后练习 ## 课后练习
> Rust By Practice支持代码在线编辑和运行并提供详细的习题解答。 > Rust By Practice支持代码在线编辑和运行并提供详细的习题解答。
> - [泛型](https://zh.practice.rs/generics-traits/generics.html) > - [泛型](https://zh-practice.course.rs/generics-traits/generics.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/generics.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/generics.md)
> - [const 泛型](https://zh.practice.rs/generics-traits/const-generics.html) > - [const 泛型](https://zh-practice.course.rs/generics-traits/const-generics.html)
> - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/const-generics.md) > - [习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/const-generics.md)

@ -381,4 +381,4 @@ 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/blob/master/solutions/generics-traits/trait-object.md)。 > [Rust By Practice](https://zh-practice.course.rs/generics-traits/trait-object.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/trait-object.md)。

@ -580,4 +580,4 @@ fn main() {
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/generics-traits/traits.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/traits.md)。 > [Rust By Practice](https://zh-practice.course.rs/generics-traits/traits.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/generics-traits/traits.md)。

@ -259,5 +259,5 @@ error: aborting due to previous error
## 课后练习 ## 课后练习
> [Rust By Practice](https://zh.practice.rs/variables.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/variables.md)。 > [Rust By Practice](https://zh-practice.course.rs/variables.html),支持代码在线编辑和运行,并提供详细的[习题解答](https://github.com/sunface/rust-by-practice/blob/master/solutions/variables.md)。

@ -49,7 +49,7 @@ $ cd lists
#### 我无法接受内存重新分配的代价 #### 我无法接受内存重新分配的代价
是的,`Vec` 当 [`capacity`](https://practice.rs/collections/vector.html#capacity) 不够时,会重新分配一块内存,然后将之前的 `Vec` 全部拷贝过去,但是对于绝大多数使用场景,要么 `Vec` 不在热点路径中,要么 `Vec` 的容量可以提前预测。 是的,`Vec` 当 [`capacity`](https://zh-practice.course.rs/collections/vector.html#capacity) 不够时,会重新分配一块内存,然后将之前的 `Vec` 全部拷贝过去,但是对于绝大多数使用场景,要么 `Vec` 不在热点路径中,要么 `Vec` 的容量可以提前预测。
对于前者,那性能如何自然无关紧要。而对于后者,我们只需要使用 `Vec::with_capacity` 提前分配足够的空间即可同时Rust 中所有的迭代器还提供了 `size_hint` 也可以解决这种问题。 对于前者,那性能如何自然无关紧要。而对于后者,我们只需要使用 `Vec::with_capacity` 提前分配足够的空间即可同时Rust 中所有的迭代器还提供了 `size_hint` 也可以解决这种问题。

Loading…
Cancel
Save