From 003a937315ec2ea2ba46c6f8e0959bdca8e6db70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=87=BA=E7=BD=91=E5=90=8D=E5=95=A6?= Date: Mon, 9 Oct 2023 18:12:26 +0800 Subject: [PATCH 01/19] typo fix --- src/practice/third-party-libs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/practice/third-party-libs.md b/src/practice/third-party-libs.md index 4d0e8a86..dab10222 100644 --- a/src/practice/third-party-libs.md +++ b/src/practice/third-party-libs.md @@ -43,7 +43,7 @@ * ORM * [rbatis/rbatis](https://github.com/rbatis/rbatis) 国内团队开发的ORM,异步、性能高、简单易上手 - * [diesel-rs/diesel](https://github.com/diesel-rs/diesel) 安全、扩展性强的Rust ORM库,支持`MySQL`、`PostgreSQL`、`SQLLite` + * [diesel-rs/diesel](https://github.com/diesel-rs/diesel) 安全、扩展性强的Rust ORM库,支持`MySQL`、`PostgreSQL`、`SQLite` * MySQL * [blackbeam/rust-mysql-simple](https://github.com/blackbeam/rust-mysql-simple) 纯Rust实现的MySQL驱动,提供连接池 From 055e921bc668dbdf501e939d1a6b885e31c4ace8 Mon Sep 17 00:00:00 2001 From: Kirk Lin Date: Tue, 10 Oct 2023 15:26:57 +0800 Subject: [PATCH 02/19] docs: update ownership.md --- src/basic/ownership/ownership.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/ownership/ownership.md b/src/basic/ownership/ownership.md index f8355cdc..c2ae814c 100644 --- a/src/basic/ownership/ownership.md +++ b/src/basic/ownership/ownership.md @@ -98,7 +98,7 @@ let s = "hello"; } // 此作用域已结束,s不再有效 ``` -简而言之,`s` 从创建伊始就开始有效,然后有效期持续到它离开作用域为止,可以看出,就作用域来说,Rust 语言跟其他编程语言没有区别。 +简而言之,`s` 从创建开始就有效,然后有效期持续到它离开作用域为止,可以看出,就作用域来说,Rust 语言跟其他编程语言没有区别。 #### 简单介绍 String 类型 From 1982ab9c4c25f8b4b2c4b8088313f40824496665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=87=BA=E7=BD=91=E5=90=8D=E5=95=A6?= Date: Tue, 10 Oct 2023 17:12:39 +0800 Subject: [PATCH 03/19] typo fix --- src/advance-practice1/multi-threads.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance-practice1/multi-threads.md b/src/advance-practice1/multi-threads.md index d2398c56..3a15d85e 100644 --- a/src/advance-practice1/multi-threads.md +++ b/src/advance-practice1/multi-threads.md @@ -247,7 +247,7 @@ impl ThreadPool { ### 存储线程 -创建 `ThreadPool` 后,下一步就是存储具体的线程,既然要存放线程,一个绕不过去的问题就是:用什么类型来存放,例如假如使用 `Vect` 来存储,那这个 `T` 应该是什么? +创建 `ThreadPool` 后,下一步就是存储具体的线程,既然要存放线程,一个绕不过去的问题就是:用什么类型来存放,例如假如使用 `Vec` 来存储,那这个 `T` 应该是什么? 估计还得探索下 `thread::spawn` 的签名,毕竟它生成并返回一个线程: From 0699beb83fe5b7d57319d8a3b46dde9a97d35440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=87=BA=E7=BD=91=E5=90=8D=E5=95=A6?= Date: Tue, 10 Oct 2023 18:41:30 +0800 Subject: [PATCH 04/19] typo fix --- src/advance-practice/channels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance-practice/channels.md b/src/advance-practice/channels.md index f92dc232..9fb24a80 100644 --- a/src/advance-practice/channels.md +++ b/src/advance-practice/channels.md @@ -73,7 +73,7 @@ async fn main() { Tokio 提供了多种消息通道,可以满足不同场景的需求: - [`mpsc`](https://docs.rs/tokio/1.15.0/tokio/sync/mpsc/index.html), 多生产者,单消费者模式 -- [`oneshot`](https://docs.rs/tokio/1.15.0/tokio/sync/oneshot/index.html), 单生产者单消费,一次只能发送一条消息 +- [`oneshot`](https://docs.rs/tokio/1.15.0/tokio/sync/oneshot/index.html), 单生产者单消费者,一次只能发送一条消息 - [`broadcast`](https://docs.rs/tokio/1/tokio/sync/broadcast/index.html),多生产者,多消费者,其中每一条发送的消息都可以被所有接收者收到,因此是广播 - [`watch`](https://docs.rs/tokio/1/tokio/sync/watch/index.html),单生产者,多消费者,只保存一条最新的消息,因此接收者只能看到最近的一条消息,例如,这种模式适用于配置文件变化的监听 From 88b2961e1898043a6c2ac996c5734af70f140227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=87=BA=E7=BD=91=E5=90=8D=E5=95=A6?= Date: Tue, 10 Oct 2023 18:45:37 +0800 Subject: [PATCH 05/19] maybe should add a comma --- src/advance-practice/channels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance-practice/channels.md b/src/advance-practice/channels.md index 9fb24a80..825d927d 100644 --- a/src/advance-practice/channels.md +++ b/src/advance-practice/channels.md @@ -73,7 +73,7 @@ async fn main() { Tokio 提供了多种消息通道,可以满足不同场景的需求: - [`mpsc`](https://docs.rs/tokio/1.15.0/tokio/sync/mpsc/index.html), 多生产者,单消费者模式 -- [`oneshot`](https://docs.rs/tokio/1.15.0/tokio/sync/oneshot/index.html), 单生产者单消费者,一次只能发送一条消息 +- [`oneshot`](https://docs.rs/tokio/1.15.0/tokio/sync/oneshot/index.html), 单生产者,单消费者,一次只能发送一条消息 - [`broadcast`](https://docs.rs/tokio/1/tokio/sync/broadcast/index.html),多生产者,多消费者,其中每一条发送的消息都可以被所有接收者收到,因此是广播 - [`watch`](https://docs.rs/tokio/1/tokio/sync/watch/index.html),单生产者,多消费者,只保存一条最新的消息,因此接收者只能看到最近的一条消息,例如,这种模式适用于配置文件变化的监听 From e27a49cf62add3fcd5cf6552a2b8a9799f3e8206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=87=BA=E7=BD=91=E5=90=8D=E5=95=A6?= Date: Tue, 10 Oct 2023 18:52:24 +0800 Subject: [PATCH 06/19] typo fix --- src/advance-practice/async.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance-practice/async.md b/src/advance-practice/async.md index c84053a9..5047a840 100644 --- a/src/advance-practice/async.md +++ b/src/advance-practice/async.md @@ -347,7 +347,7 @@ impl Future for Delay { #### 处理 wake 通知 -下面,让我们更新 mint-tokio 服务,让它能接收 wake 通知:当 `waker.wake()` 被调用后,相关联的任务会被放入执行器的队列中,然后等待执行器的调用执行。 +下面,让我们更新 mini-tokio 服务,让它能接收 wake 通知:当 `waker.wake()` 被调用后,相关联的任务会被放入执行器的队列中,然后等待执行器的调用执行。 为了实现这一点,我们将使用消息通道来排队存储这些被唤醒并等待调度的任务。有一点需要注意,从消息通道接收消息的线程(执行器所在的线程)和发送消息的线程(唤醒任务时所在的线程)可能是不同的,因此消息( `Waker` )必须要实现 `Send`和 `Sync`,才能跨线程使用。 From fa743b7d704e00830ce4659eb3616eb83593a64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=87=BA=E7=BD=91=E5=90=8D=E5=95=A6?= Date: Tue, 10 Oct 2023 18:56:10 +0800 Subject: [PATCH 07/19] typo fix --- src/advance-practice/async.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance-practice/async.md b/src/advance-practice/async.md index 5047a840..1da47d04 100644 --- a/src/advance-practice/async.md +++ b/src/advance-practice/async.md @@ -522,7 +522,7 @@ async fn main() { 我们之前的 `Delay` 实现中,会在每一次 `poll` 调用时都生成一个新的线程。这么做问题不大,但是当 `poll` 调用较多时会出现明显的性能问题!一个解决方法就是记录你是否已经生成了一个线程,然后只有在没有生成时才去创建一个新的线程。但是一旦这么做,就必须确保线程的 `Waker` 在后续 `poll` 调用中被正确更新,否则你无法唤醒最近的 `Waker` ! -这一段大家可能会看得云里雾里的,没办法,原文就饶来绕去,好在终于可以看代码了。。我们可以通过代码来解决疑惑: +这一段大家可能会看得云里雾里的,没办法,原文就绕来绕去,好在终于可以看代码了。。我们可以通过代码来解决疑惑: ```rust use std::future::Future; From f0f21578b6acf6f71c03b107a9ceb9f95ec7ce1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=87=BA=E7=BD=91=E5=90=8D=E5=95=A6?= Date: Tue, 10 Oct 2023 19:29:53 +0800 Subject: [PATCH 08/19] typo fix --- src/difficulties/eq.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/difficulties/eq.md b/src/difficulties/eq.md index 378c1077..ba743e26 100644 --- a/src/difficulties/eq.md +++ b/src/difficulties/eq.md @@ -118,10 +118,10 @@ fn main() { 大家猜猜哪一行会输出 :) 至于 `NaN` 为何不能比较,这个原因就比较复杂了( 有读者会说,其实就是你不知道,我只能义正严辞的说:咦?你怎么知道 :P )。 -既然浮点数有一个值不可以比较相等性,那它自然只能实现 `PartialEq` 而不能实现 `Eq` 了,以此类推,如果我们的类型也有这种特殊要求,那也应该这么作。 +既然浮点数有一个值不可以比较相等性,那它自然只能实现 `PartialEq` 而不能实现 `Eq` 了,以此类推,如果我们的类型也有这种特殊要求,那也应该这么做。 ### Ord 和 PartialOrd 事实上,还有一对与 `Eq/PartialEq` 非常类似的特征,它们可以用于 `<`、`<=`、`>` 和 `>=` 比较,至于哪个类型实现了 `PartialOrd` 却没有实现 `Ord` 就交给大家自己来思考了:) -> 小提示:Ord 意味着一个类型的所有值都可以进行排序,而 PartialOrd 则不然 \ No newline at end of file +> 小提示:Ord 意味着一个类型的所有值都可以进行排序,而 PartialOrd 则不然 From 9e69201cd7a871eb4f9531009c10f69d39fa67bb Mon Sep 17 00:00:00 2001 From: Eucalypt Date: Wed, 11 Oct 2023 16:43:26 +0800 Subject: [PATCH 09/19] translation(appendix/rust-versions) : 1.73 --- src/SUMMARY.md | 1 + src/appendix/rust-versions/1.72.md | 2 +- src/appendix/rust-versions/1.73.md | 84 ++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/appendix/rust-versions/1.73.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 7fa5ef01..1da57f17 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -376,3 +376,4 @@ - [1.70](appendix/rust-versions/1.70.md) - [1.71](appendix/rust-versions/1.71.md) - [1.72](appendix/rust-versions/1.72.md) + - [1.73](appendix/rust-versions/1.73.md) diff --git a/src/appendix/rust-versions/1.72.md b/src/appendix/rust-versions/1.72.md index 720f0f8c..b345b56c 100644 --- a/src/appendix/rust-versions/1.72.md +++ b/src/appendix/rust-versions/1.72.md @@ -41,7 +41,7 @@ error: could not compile `my-project` (bin "my-project") due to previous error 几个原本由 Clippy 提供的 lints,提升到 rustc 里: -* [`clippy::undropped_manually_drops`](https://rust-lang.github.io/rust-clippy/rust-1.71.0/index.html#undropped_manually_drops) => [undropped-manually-drops](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/deny-by-default.html#undropped-manually-drops) (deny) +* [`clippy::undropped_manually_drops`](https://rust-lang.github.io/rust-clippy/rust-1.71.0/index.html#undropped_manually_drops) => [`undropped-manually-drops`](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/deny-by-default.html#undropped-manually-drops) (deny) * 无作用的 `ManullyDrop` * [`clippy::invalid_utf8_in_unchecked`](https://rust-lang.github.io/rust-clippy/rust-1.71.0/index.html#invalid_utf8_in_unchecked) => [`invalid_from_utf8_unchecked`](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/deny-by-default.html#invalid-from-utf8-unchecked) (deny) 或 [`invalid_from_utf8`](https://doc.rust-lang.org/1.72.0/rustc/lints/listing/warn-by-default.html#invalid-from-utf8) (warn) * 检查调用 `std::str::from_utf8_unchecked` 和 `std::str::from_utf8_unchecked_mut` 转换不合法的 UTF-8 字面量,这会违反了 safety 前提,导致未定义行为 diff --git a/src/appendix/rust-versions/1.73.md b/src/appendix/rust-versions/1.73.md new file mode 100644 index 00000000..f89f018a --- /dev/null +++ b/src/appendix/rust-versions/1.73.md @@ -0,0 +1,84 @@ +# Rust 新版解读 | 1.73 | panic 报错展示优化 + +> Rust 1.73 官方 release doc: [Announcing Rust 1.73.0 | Rust Blog](https://blog.rust-lang.org/2023/10/05/Rust-1.73.0.html) + +通过 [rustup](https://www.rust-lang.org/tools/install) 安装的同学可以使用以下命令升级到 1.73 版本: + +```shell +$ rustup update stable +``` + +## 更简洁的 panic 报错信息 + +默认的 panic handler 会把报错信息单独列出一行,当报错信息很长、包含多行或者嵌套结构的时候可读性会更强。 + +```rust +fn main() { + let file = "ferris.txt"; + panic!("oh no! {file:?} not found!"); +} +``` + +Rust 1.73 之前的: +```shell +thread 'main' panicked at 'oh no! "ferris.txt" not found!', src/main.rs:3:5 +``` + +Rust 1.73 之后的: +```shell +thread 'main' panicked at src/main.rs:3:5: +oh no! "ferris.txt" not found! +``` + +另外,由 `assert_eq` 和 `assert_ne` 产生的 panic 消息也把自定义信息部分(第三个参数)的展示位置改动了一下: + +```rust +fn main() { + assert_eq!("🦀", "🐟", "ferris is not a fish"); +} +``` + +Rust 1.73 之前的: +```shell +thread 'main' panicked at 'assertion failed: `(left == right)` + left: `"🦀"`, +right: `"🐟"`: ferris is not a fish', src/main.rs:2:5 +``` + +Rust 1.73 之后的: +```shell +thread 'main' panicked at src/main.rs:2:5: +assertion `left == right` failed: ferris is not a fish + left: "🦀" +right: "🐟" +``` + +## 线程局部初始化 + +如 [RFC 3184](https://github.com/rust-lang/rfcs/blob/master/text/3184-thread-local-cell-methods.md) 提案, `LocalKey>` 和 `LocalKey>` 现在可以直接用 `get()`, `set()`, `take()` 和 `replace()` 方法来操作,不再需要写 `with(|inner|...)` 的闭包形式。声明线程静态局部变量的宏 `thread_local!` 内部就是使用的就是 `LocalKey`。 + +新的方法让代码更简洁,也避免了默认值在新线程运行额外的初始化代码。 + +```rust +thread_local! { + static THINGS: Cell> = Cell::new(Vec::new()); +} + +fn f() { + // before: + THINGS.with(|i| i.set(vec![1, 2, 3])); + // now: + THINGS.set(vec![1, 2, 3]); + + // ... + + // before: + let v = THINGS.with(|i| i.take()); + // now: + let v: Vec = THINGS.take(); +} +``` + +## Others + +其它更新细节,和稳定的API列表,参考[原Blog](https://blog.rust-lang.org/2023/10/05/Rust-1.73.0.html#stabilized-apis) From 6e651b161f2a85b0f73eaac761cf0b55fc430d90 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Sat, 14 Oct 2023 12:33:00 +0800 Subject: [PATCH 10/19] chore: add color to scrollbar thumb --- theme/style.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/theme/style.css b/theme/style.css index d9b5952a..ea8bc6e3 100644 --- a/theme/style.css +++ b/theme/style.css @@ -65,6 +65,10 @@ width: 5px; height: 5px; } +::-webkit-scrollbar-thumb { + background: #99ccff; + border-radius: 3px; +} /* 表格靠左对齐 */ table { From b05a1f41b8e25f4a0922d013bfca475a10cd0369 Mon Sep 17 00:00:00 2001 From: butonly Date: Sun, 15 Oct 2023 01:14:13 -0500 Subject: [PATCH 11/19] Update cell-refcell.md --- src/advance/smart-pointer/cell-refcell.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance/smart-pointer/cell-refcell.md b/src/advance/smart-pointer/cell-refcell.md index 76ffe26a..99d87398 100644 --- a/src/advance/smart-pointer/cell-refcell.md +++ b/src/advance/smart-pointer/cell-refcell.md @@ -144,7 +144,7 @@ fn main() { } ``` -上面的代码会报错,因为我们不能对一个不可变的值进行可变借用,这会破坏 Rust 的安全性保证,相反,你可以对一个可变值进行不可变借用。原因是:当值不可变时,可能会有多个不可变的引用指向它,此时若将修改其中一个为可变的,会造成可变引用与不可变引用共存的情况;而当值可变时,最多只会有一个可变引用指向它,将其修改为不可变,那么最终依然是只有一个不可变的引用指向它。 +上面的代码会报错,因为我们不能对一个不可变的值进行可变借用,这会破坏 Rust 的安全性保证,相反,你可以对一个可变值进行不可变借用。原因是:当值不可变时,可能会有多个不可变的引用指向它,此时若将其中一个修改为可变的,会造成可变引用与不可变引用共存的情况;而当值可变时,最多只会有一个可变引用指向它,将其修改为不可变,那么最终依然是只有一个不可变的引用指向它。 虽然基本借用规则是 Rust 的基石,然而在某些场景中,一个值可以在其方法内部被修改,同时对于其它代码不可变,是很有用的: From 724341f2165c322cbfb0829f093618da8697911b Mon Sep 17 00:00:00 2001 From: WB20230410002 Date: Wed, 18 Oct 2023 10:12:04 +0800 Subject: [PATCH 12/19] fix: update enum.md --- src/basic/compound-type/enum.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/basic/compound-type/enum.md b/src/basic/compound-type/enum.md index 31fe139b..fd1efb08 100644 --- a/src/basic/compound-type/enum.md +++ b/src/basic/compound-type/enum.md @@ -41,6 +41,7 @@ fn main() { } fn print_suit(card: PokerSuit) { + // 需要在定义 enum PokerSuit 的上面添加上 #[derive(Debug)],否则会报 card 没有实现 Debug println!("{:?}",card); } ``` From 16586f8c3b804e604341542541277b15410055c7 Mon Sep 17 00:00:00 2001 From: kerwincsc Date: Wed, 18 Oct 2023 20:19:36 +0800 Subject: [PATCH 13/19] Update panic.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实际上包含 `panic!` 行的前面的空格的 --- src/basic/result-error/panic.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/result-error/panic.md b/src/basic/result-error/panic.md index 790f16a0..5b1199fb 100644 --- a/src/basic/result-error/panic.md +++ b/src/basic/result-error/panic.md @@ -61,7 +61,7 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace 以上信息包含了两条重要信息: -- `main` 函数所在的线程崩溃了,发生的代码位置是 `src/main.rs` 中的第 2 行第 5 个字符(去除该行前面的空字符) +- `main` 函数所在的线程崩溃了,发生的代码位置是 `src/main.rs` 中的第 2 行第 5 个字符(包含该行前面的空字符) - 在使用时加上一个环境变量可以获取更详细的栈展开信息: - Linux/macOS 等 UNIX 系统: `RUST_BACKTRACE=1 cargo run` - Windows 系统(PowerShell): `$env:RUST_BACKTRACE=1 ; cargo run` From 943ee7bf1ade9ea501cb53b78f28a0a5e5ae2975 Mon Sep 17 00:00:00 2001 From: kerwincsc Date: Sat, 28 Oct 2023 10:07:09 +0800 Subject: [PATCH 14/19] Update module.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 强调同级和同名 --- src/basic/crate-module/module.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/crate-module/module.md b/src/basic/crate-module/module.md index d28f6eaa..38c1e83a 100644 --- a/src/basic/crate-module/module.md +++ b/src/basic/crate-module/module.md @@ -349,7 +349,7 @@ error[E0583]: file not found for module `front_of_house` 是的,如果需要将文件夹作为一个模块,我们需要进行显示指定暴露哪些子模块。按照上述的报错信息,我们有两种方法: - 在 `front_of_house` 目录里创建一个 `mod.rs`,如果你使用的 `rustc` 版本 `1.30` 之前,这是唯一的方法。 -- 在 `front_of_house` 同级目录里创建一个与模块(目录)同名的 rs 文件 `front_of_house.rs`,在新版本里,更建议使用这样的命名方式来避免项目中存在大量同名的 `mod.rs` 文件( Python 点了个 `踩`)。 +- 在 `front_of_house` **同级**目录里创建一个与模块(目录)**同名**的 rs 文件 `front_of_house.rs`,在新版本里,更建议使用这样的命名方式来避免项目中存在大量同名的 `mod.rs` 文件( Python 点了个 `踩`)。 而无论是上述哪个方式创建的文件,其内容都是一样的,你需要定义你的子模块(子模块名与文件名相同): From f1eb77192727ddd2f25f9d8c9c9d1c4c4bda5f21 Mon Sep 17 00:00:00 2001 From: asthetik Date: Sun, 29 Oct 2023 15:35:19 +0800 Subject: [PATCH 15/19] Eliminate compiler warnings --- src/advance/functional-programing/iterator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance/functional-programing/iterator.md b/src/advance/functional-programing/iterator.md index 00ca73cc..8772541f 100644 --- a/src/advance/functional-programing/iterator.md +++ b/src/advance/functional-programing/iterator.md @@ -435,7 +435,7 @@ let val = v.iter() // 每两个元素剔除一个 // [1, 3, 5] .filter(|&(idx, _)| idx % 2 == 0) - .map(|(idx, val)| val) + .map(|(_, val)| val) // 累加 1+3+5 = 9 .fold(0u64, |sum, acm| sum + acm); From 6ebdb06b7ab8fbf0f094d26a9c4c5788503137b0 Mon Sep 17 00:00:00 2001 From: Sancpp <67474179+sancppp@users.noreply.github.com> Date: Mon, 30 Oct 2023 08:12:19 -0500 Subject: [PATCH 16/19] Update ownership.md update error info --- src/basic/ownership/ownership.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/basic/ownership/ownership.md b/src/basic/ownership/ownership.md index f8355cdc..633af334 100644 --- a/src/basic/ownership/ownership.md +++ b/src/basic/ownership/ownership.md @@ -181,17 +181,24 @@ println!("{}, world!", s1); 由于 Rust 禁止你使用无效的引用,你会看到以下的错误: ```console -error[E0382]: use of moved value: `s1` +error[E0382]: borrow of moved value: `s1` --> src/main.rs:5:28 | +2 | let s1 = String::from("hello"); + | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait 3 | let s2 = s1; - | -- value moved here + | -- value moved here 4 | 5 | println!("{}, world!", s1); - | ^^ value used here after move + | ^^ value borrowed here after move | - = note: move occurs because `s1` has type `std::string::String`, which does - not implement the `Copy` trait + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider cloning the value if the performance cost is acceptable + | +3 | let s2 = s1.clone(); + | ++++++++ + +For more information about this error, try `rustc --explain E0382`. ``` 现在再回头看看之前的规则,相信大家已经有了更深刻的理解: From 6158345e9b5cf7ac6e8dbf1201c7231313e39444 Mon Sep 17 00:00:00 2001 From: Gengen Wang <35788677+XuGuangnian@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:28:42 +0800 Subject: [PATCH 17/19] Update some-thoughts.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除 “最” --- src/some-thoughts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/some-thoughts.md b/src/some-thoughts.md index 4e6f6756..da031a8e 100644 --- a/src/some-thoughts.md +++ b/src/some-thoughts.md @@ -16,7 +16,7 @@ 这些特性每一个都不简单, **Datav 就是为了解决这些问题而生**。 -> Datav 不是全世界最好的可观测性和数据可视化平台,这毫无疑问,至少目前不是。但是它对最开发者最友好,并且支持丰富的可编程性的平台 +> Datav 不是全世界最好的可观测性和数据可视化平台,这毫无疑问,至少目前不是。但是它对开发者最友好,并且支持丰富的可编程性的平台 > > 当一个产品它的代码结构清晰简洁、架构干净、使用的技术符合时代主流、文档齐全,当一个产品在各种使用细节上都为开发者专门设计过,当一个产品允许各种深度可定制时,我们可以称其开发者友好 From 5506ac33cf36da5c04f5a36f9cff10e9f94f2ccf Mon Sep 17 00:00:00 2001 From: Gengen Wang <35788677+XuGuangnian@users.noreply.github.com> Date: Mon, 13 Nov 2023 13:53:40 +0800 Subject: [PATCH 18/19] fix cargo expand in macro.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与前文不符,应使用 `cargo expand --bin hello_macro` in hello_macro root directory --- src/advance/macro.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance/macro.md b/src/advance/macro.md index 31cddee5..1aa43aab 100644 --- a/src/advance/macro.md +++ b/src/advance/macro.md @@ -451,7 +451,7 @@ fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream { 在运行之前,可以显示用 expand 展开宏,观察是否有错误或是否符合预期: ```shell -$ cargo expand --lib hello_macro +$ cargo expand --bin hello_macro ``` ```rust struct Sunfei; From 21424765409293da90ad9502aa7add973d3f5b33 Mon Sep 17 00:00:00 2001 From: Sunface Date: Thu, 16 Nov 2023 13:09:36 +0800 Subject: [PATCH 19/19] Update src/advance/macro.md --- src/advance/macro.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/advance/macro.md b/src/advance/macro.md index 1aa43aab..92570a8c 100644 --- a/src/advance/macro.md +++ b/src/advance/macro.md @@ -449,7 +449,7 @@ fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream { - `#name` 可能是一个表达式,我们需要它的字面值形式 - 可以减少一次 `String` 带来的内存分配 -在运行之前,可以显示用 expand 展开宏,观察是否有错误或是否符合预期: +在运行之前,可以先用 expand 展开宏,观察是否有错误或符合预期: ```shell $ cargo expand --bin hello_macro ```