From 88738f4075399394b0de67a9bcab7f3ba2679345 Mon Sep 17 00:00:00 2001 From: KaiserY Date: Sun, 25 May 2025 13:36:49 +0800 Subject: [PATCH] wip: 2024 edition --- src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md | 4 ++-- src/ch21-02-multithreaded.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index bfda725..5102550 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -103,7 +103,7 @@ 在这个修改之前,外部代码需要使用路径 `restaurant::front_of_house::hosting::add_to_waitlist()` 来调用 `add_to_waitlist` 函数,并且还需要将 `front_of_house` 模块标记为 `pub`。现在这个 `pub use` 从根模块重导出了 `hosting` 模块,外部代码现在可以使用路径 `restaurant::hosting::add_to_waitlist`。 -当你代码的内部结构与调用你代码的程序员所想象的结构不同时,重导出会很有用。例如,在这个餐馆的比喻中,经营餐馆的人会想到“前台”和“后台”。但顾客在光顾一家餐馆时,可能不会以这些术语来考虑餐馆的各个部分。使用 `pub use`,我们可以使用一种结构编写代码,却将不同的结构形式暴露出来。这样做使我们的库井井有条,也使开发这个库的程序员和调用这个库的程序员都更加方便。在[“使用 `pub use` 导出合适的公有 API”][ch14-pub-use]部分让我们再看另一个 `pub use` 的例子来了解这如何影响 crate 的文档。 +当你代码的内部结构与调用你代码的程序员所想象的结构不同时,重导出会很有用。例如,在这个餐馆的比喻中,经营餐馆的人会想到“前台”和“后台”。但顾客在光顾一家餐馆时,可能不会以这些术语来考虑餐馆的各个部分。使用 `pub use`,我们可以使用一种结构编写代码,却将不同的结构形式暴露出来。这样做使我们的库井井有条,也使开发这个库的程序员和调用这个库的程序员都更加方便。在[“使用 `pub use` 导出便捷的公有 API”][ch14-pub-use]部分让我们再看另一个 `pub use` 的例子来了解这如何影响 crate 的文档。 ### 使用外部包 @@ -189,6 +189,6 @@ use std::collections::*; glob 运算符经常用于测试模块 `tests` 中,这时会将所有内容引入作用域;我们将在第十一章“如何编写测试”部分讲解。glob 运算符有时也用于 prelude 模式;查看[标准库中的文档](https://doc.rust-lang.org/std/prelude/index.html#other-preludes)了解这个模式的更多细节。 -[ch14-pub-use]: ch14-02-publishing-to-crates-io.html#使用-pub-use-导出合适的公有-api +[ch14-pub-use]: ch14-02-publishing-to-crates-io.html#使用-pub-use-导出便捷的公有-api [rand]: ch02-00-guessing-game-tutorial.html#生成一个随机数 [writing-tests]: ch11-01-writing-tests.html#如何编写测试 diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index 96c35ff..b526733 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -121,7 +121,7 @@ 这里发生错误是因为并没有 `ThreadPool` 上的 `execute` 方法。回忆 [“创建有限数量的线程”](#创建有限数量的线程) 部分我们决定线程池应该有与 `thread::spawn` 类似的接口,同时我们将实现 `execute` 函数来获取传递的闭包并将其传递给池中的空闲线程执行。 -我们会在 `ThreadPool` 上定义 `execute` 函数来获取一个闭包参数。回忆第十三章的 [“将被捕获的值移出闭包和 `Fn` trait”][fn-traits] 部分,闭包作为参数时可以使用三个不同的 trait:`Fn`、`FnMut` 和 `FnOnce`。我们需要决定这里应该使用哪种闭包。最终需要实现的类似于标准库的 `thread::spawn`,所以我们可以观察 `thread::spawn` 的签名在其参数中使用了何种 bound。查看文档会发现: +我们会在 `ThreadPool` 上定义 `execute` 函数来获取一个闭包参数。回忆第十三章的 [“将捕获的值移出闭包和 `Fn` trait”][fn-traits] 部分,闭包作为参数时可以使用三个不同的 trait:`Fn`、`FnMut` 和 `FnOnce`。我们需要决定这里应该使用哪种闭包。最终需要实现的类似于标准库的 `thread::spawn`,所以我们可以观察 `thread::spawn` 的签名在其参数中使用了何种 bound。查看文档会发现: ```rust,ignore pub fn spawn(f: F) -> JoinHandle @@ -395,6 +395,6 @@ Worker 2 got a job; executing. [creating-type-synonyms-with-type-aliases]: ch20-03-advanced-types.html#使用类型别名创建类型同义词 [integer-types]: ch03-02-data-types.html#整型 -[fn-traits]: ch13-01-closures.html#将被捕获的值移出闭包和-fn-trait +[fn-traits]: ch13-01-closures.html#将捕获的值移出闭包和-fn-trait [builder]: https://doc.rust-lang.org/std/thread/struct.Builder.html [builder-spawn]: https://doc.rust-lang.org/std/thread/struct.Builder.html#method.spawn