1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-18 20:39:35 +02:00

zh-CN: Day 2 Translations (#1319)

Professional translations for missing day 2 entries #324
This is a new attempt, after fixing the original .po file
(https://github.com/google/comprehensive-rust/pull/1312).
The diff is large mostly because of the normalization (line breaks,
etc.)

Co-authored-by: Zhang SIQI <zhangsiqi1988@gmail.com>
This commit is contained in:
Henri F 2023-10-08 23:10:17 -07:00 committed by GitHub
parent fdae99c3d2
commit 78dfe60bb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Comprehensive Rust 🦀\n"
"POT-Creation-Date: 2023-10-06T11:02:48-07:00\n"
"POT-Creation-Date: 2023-10-06T12:07:21-07:00\n"
"PO-Revision-Date: 2023-09-11 10:30-0700\n"
"Last-Translator: \n"
"Language-Team: Language zh-Hans\n"
@ -5958,11 +5958,11 @@ msgid ""
"It is only the ownership that moves. Whether any machine code is generated "
"to manipulate the data itself is a matter of optimization, and such copies "
"are aggressively optimized away."
msgstr ""
msgstr "只有所有权发生了转移。是否会生成任何机器码来操控数据本身是一个优化方面的问题,系统会主动优化此类副本。"
#: src/ownership/move-semantics.md:25
msgid "Simple values (such as integers) can be marked `Copy` (see later slides)."
msgstr ""
msgstr "简单的值(例如整数)可以标记为“Copy”(请看后续幻灯片)。"
#: src/ownership/move-semantics.md:27
msgid "In Rust, clones are explicit (by using `clone`)."
@ -6071,7 +6071,7 @@ msgid ""
"C++ has made a slightly different choice than Rust. Because `=` copies data, "
"the string data has to be cloned. Otherwise we would get a double-free when "
"either string goes out of scope."
msgstr ""
msgstr "C++ 做出了与 Rust 略有不同的选择。由于“=”会复制数据,因此必须克隆字符串数据。否则,当任一字符串超出范围时,便会出现二次释放。"
#: src/ownership/double-free-modern-cpp.md:61
msgid ""
@ -6081,12 +6081,15 @@ msgid ""
"move, `s1` would be in a valid but unspecified state. Unlike Rust, the "
"programmer is allowed to keep using `s1`."
msgstr ""
"C++ "
"还包含[“std::move”](https://en.cppreference.com/w/cpp/utility/move),它用于指示何时可以移动某个值。如果示例为“s2 "
"= std::move(s1)”,则不会发生堆分配。移动后,“s1”将处于有效但未指定的状态。与 Rust 不同,程序员可以继续使用“s1”。"
#: src/ownership/double-free-modern-cpp.md:66
msgid ""
"Unlike Rust, `=` in C++ can run arbitrary code as determined by the type "
"which is being copied or moved."
msgstr ""
msgstr "与 Rust 不同,使用 C++ 时,“=”可以运行任意代码,具体取决于要复制或移动的类型。"
#: src/ownership/moves-function-calls.md:3
msgid ""
@ -6517,47 +6520,47 @@ msgstr ""
#: src/structs.md:33
msgid "Structs work like in C or C++."
msgstr ""
msgstr "结构体的运作方式与使用 C 或 C++ 时类似。"
#: src/structs.md:34
msgid "Like in C++, and unlike in C, no typedef is needed to define a type."
msgstr ""
msgstr "不需要 typedef 即可定义类型,这与使用 C++ 类似,但与使用 C 不同。"
#: src/structs.md:35
msgid "Unlike in C++, there is no inheritance between structs."
msgstr ""
msgstr "与使用 C++ 不同的是,结构体之间没有继承关系。"
#: src/structs.md:36
msgid ""
"Methods are defined in an `impl` block, which we will see in following "
"slides."
msgstr ""
msgstr "方法是在“impl”块中进行定义的,我们将在后面的幻灯片中看到。"
#: src/structs.md:37
msgid ""
"This may be a good time to let people know there are different types of "
"structs. "
msgstr ""
msgstr "这时可能很适合告诉学员存在不同类型的结构体。"
#: src/structs.md:38
msgid ""
"Zero-sized structs `e.g., struct Foo;` might be used when implementing a "
"trait on some type but don’t have any data that you want to store in the "
"value itself. "
msgstr ""
msgstr "针对某类型实现 trait 时,可能会使用大小为零的结构体“e.g., struct Foo;”,但其中没有任何您要储存在值本身中的数据。"
#: src/structs.md:39
msgid ""
"The next slide will introduce Tuple structs, used when the field names are "
"not important."
msgstr ""
msgstr "下一张幻灯片将介绍元组结构体,当字段名称不重要时使用。"
#: src/structs.md:40
msgid ""
"The syntax `..peter` allows us to copy the majority of the fields from the "
"old struct without having to explicitly type it all out. It must always be "
"the last element."
msgstr ""
msgstr "通过语法“..peter”,我们可以从旧结构体复制大部分字段,而无需明确地输入所有字段。它必须始终是最后一个元素。"
#: src/structs/tuple-structs.md:3
msgid "If the field names are unimportant, you can use a tuple struct:"
@ -6674,13 +6677,13 @@ msgstr ""
msgid ""
"The `new` function could be written using `Self` as a type, as it is "
"interchangeable with the struct type name"
msgstr ""
msgstr "在编写“new”函数时可以使用“Self”作为类型,因为它可以与结构体类型名称互换"
#: src/structs/field-shorthand.md:41
msgid ""
"Implement the `Default` trait for the struct. Define some fields and use the "
"default values for the other fields."
msgstr ""
msgstr "为结构体实现“Default”trait。定义一些字段并对其他字段使用默认值。"
#: src/structs/field-shorthand.md:43
msgid ""
@ -6712,23 +6715,23 @@ msgstr ""
#: src/structs/field-shorthand.md:68
msgid "Methods are defined in the `impl` block."
msgstr ""
msgstr "方法是在“impl”块中进行定义的。"
#: src/structs/field-shorthand.md:69
msgid ""
"Use struct update syntax to define a new structure using `peter`. Note that "
"the variable `peter` will no longer be accessible afterwards."
msgstr ""
msgstr "使用结构体更新语法以利用“peter”定义一个新结构。请注意,之后将无法再访问变量“peter”。"
#: src/structs/field-shorthand.md:70
msgid "Use `{:#?}` when printing structs to request the `Debug` representation."
msgstr ""
msgstr "在输出结构体时,使用“{:#?}”来请求“Debug”表示法。"
#: src/methods.md:3
msgid ""
"Rust allows you to associate functions with your new types. You do this with "
"an `impl` block:"
msgstr ""
msgstr "Rust 允许您将函数与新类型相关联。您可以使用“impl”块来执行此操作:"
#: src/methods.md:6
msgid ""
@ -6757,70 +6760,70 @@ msgstr ""
#: src/methods.md:31
msgid "It can be helpful to introduce methods by comparing them to functions."
msgstr ""
msgstr "引入方法时,将方法与函数进行比较会很有帮助。"
#: src/methods.md:32
msgid ""
"Methods are called on an instance of a type (such as a struct or enum), the "
"first parameter represents the instance as `self`."
msgstr ""
msgstr "在某种类型(例如结构体或枚举)的实例上调用方法,第一个参数将该实例表示为“self”。"
#: src/methods.md:33
msgid ""
"Developers may choose to use methods to take advantage of method receiver "
"syntax and to help keep them more organized. By using methods we can keep "
"all the implementation code in one predictable place."
msgstr ""
msgstr "开发者可能会选择使用方法,以便利用方法接收器语法并让方法更有条理。通过使用方法,我们可以将所有实现代码保存在一个可预测的位置。"
#: src/methods.md:34
msgid "Point out the use of the keyword `self`, a method receiver."
msgstr ""
msgstr "指出关键字“self”的用法,它是一种方法接收器。"
#: src/methods.md:35
msgid ""
"Show that it is an abbreviated term for `self: Self` and perhaps show how "
"the struct name could also be used."
msgstr ""
msgstr "显示它是“self: Self”的缩写术语,或许要显示结构体名称的可能用法。"
#: src/methods.md:36
msgid ""
"Explain that `Self` is a type alias for the type the `impl` block is in and "
"can be used elsewhere in the block."
msgstr ""
msgstr "说明“Self”是“impl”块所属类型的类型别名,可以在块中的其他位置使用。"
#: src/methods.md:37
msgid ""
"Note how `self` is used like other structs and dot notation can be used to "
"refer to individual fields."
msgstr ""
msgstr "指出“self”的使用方式与其他结构体一样,并且可以使用点表示法来指代各个字段。"
#: src/methods.md:38
msgid ""
"This might be a good time to demonstrate how the `&self` differs from `self` "
"by modifying the code and trying to run say_hello twice."
msgstr ""
msgstr "这可能是演示“&self”和“self”差别的好时机,您只要修改代码并尝试执行 say_hello 两次即可。"
#: src/methods.md:39
msgid "We describe the distinction between method receivers next."
msgstr ""
msgstr "下面,我们将介绍方法接收器之间的区别。"
#: src/methods/receiver.md:3
msgid ""
"The `&self` above indicates that the method borrows the object immutably. "
"There are other possible receivers for a method:"
msgstr ""
msgstr "上面的“&self”表明该方法以不可变的方式借用了对象。还有其他可能的方法接收器:"
#: src/methods/receiver.md:6
msgid ""
"`&self`: borrows the object from the caller using a shared and immutable "
"reference. The object can be used again afterwards."
msgstr ""
msgstr "“&self”:使用不可变的共享引用从调用方借用对象。之后可以再次使用该对象。"
#: src/methods/receiver.md:8
msgid ""
"`&mut self`: borrows the object from the caller using a unique and mutable "
"reference. The object can be used again afterwards."
msgstr ""
msgstr "“&mut self”:使用唯一的可变引用从调用方借用对象。之后可以再次使用该对象。"
#: src/methods/receiver.md:10
msgid ""
@ -6829,23 +6832,28 @@ msgid ""
"(deallocated) when the method returns, unless its ownership is explicitly "
"transmitted. Complete ownership does not automatically mean mutability."
msgstr ""
"“self”:获取对象的所有权并将其从调用方移出。该方法会成为对象的所有者。除非明确转移对象的所有权,否则在该方法返回时,对象将被丢弃(取消分配)。具备完全所有权,不自动等同于具备可变性。"
#: src/methods/receiver.md:14
msgid "`mut self`: same as above, but the method can mutate the object. "
msgstr ""
msgstr "“mut self”:同上,但该方法可以改变对象。"
#: src/methods/receiver.md:15
msgid ""
"No receiver: this becomes a static method on the struct. Typically used to "
"create constructors which are called `new` by convention."
msgstr ""
msgstr "无接收器:这将变为结构体上的静态方法。通常用于创建构造函数,按惯例被称为“new”。"
#: src/methods/receiver.md:18
#, fuzzy
msgid ""
"Beyond variants on `self`, there are also [special wrapper "
"types](https://doc.rust-lang.org/reference/special-types-and-traits.html) "
"allowed to be receiver types, such as `Box<Self>`."
msgstr ""
"除“self”的变体外,还可以将[特殊封装容器类型](https://doc.rust-lang.org/reference/special-types-and-traits.html)作为接收器类型,例如“Box\n"
"\n"
"”。"
#: src/methods/receiver.md:24
msgid ""
@ -6854,6 +6862,8 @@ msgid ""
"and `self` is no exception. It isn't possible to reference a struct from "
"multiple locations and call a mutating (`&mut self`) method on it."
msgstr ""
"建议强调“共享且不可变”和“唯一且可变”。由于借用检查器规则的原因,这些约束在 Rust "
"中总是一起出现,而“self”也不例外。您无法从多个位置引用结构体并对其调用一项改变(“&mut self”)方法。"
#: src/methods/example.md:3
msgid ""
@ -6903,18 +6913,18 @@ msgstr ""
#: src/methods/example.md:47
msgid "All four methods here use a different method receiver."
msgstr ""
msgstr "这里的所有四种方法都使用一个不同的方法接收器。"
#: src/methods/example.md:48
msgid ""
"You can point out how that changes what the function can do with the "
"variable values and if/how it can be used again in `main`."
msgstr ""
msgstr "您可以指出这会如何改变函数可对变量值采取的操作,以及是否/如何能够在“main”中再次使用该函数。"
#: src/methods/example.md:49
msgid ""
"You can showcase the error that appears when trying to call `finish` twice."
msgstr ""
msgstr "您可以展示在尝试调用“finish”两次时出现的错误。"
#: src/methods/example.md:50
msgid ""
@ -6923,12 +6933,14 @@ msgid ""
"referencing and dereferencing when calling methods. Rust automatically adds "
"in the `&`, `*`, `muts` so that that object matches the method signature."
msgstr ""
"请注意,尽管方法接收器不同,但是非静态函数在 main 函数体中的调用方式相同。Rust "
"支持在调用方法时自动引用和解引用,并会自动加入“&”“\\*”和“muts”以便该对象与方法签名匹配。"
#: src/methods/example.md:51
msgid ""
"You might point out that `print_laps` is using a vector that is iterated "
"over. We describe vectors in more detail in the afternoon. "
msgstr ""
msgstr "您或许可以指出“print_laps”使用的是不断迭代的矢量。我们将在下午详细说明这些矢量。"
#: src/exercises/day-2/morning.md:1
msgid "Day 2: Morning Exercises"
@ -6940,17 +6952,21 @@ msgstr "我们将考虑以下两种场景:"
#: src/exercises/day-2/morning.md:5
msgid "Storing books and querying the collection"
msgstr ""
msgstr "存储图书和查询馆藏"
#: src/exercises/day-2/morning.md:7
msgid "Keeping track of health statistics for patients"
msgstr ""
msgstr "跟踪患者的健康统计信息"
#: src/exercises/day-2/book-library.md:3
#, fuzzy
msgid ""
"We will learn much more about structs and the `Vec<T>` type tomorrow. For "
"now, you just need to know part of its API:"
msgstr ""
"我们明天会更详细地介绍结构体和“Vec\n"
"\n"
"”类型。目前,您只需了解其 API 的一部分:"
#: src/exercises/day-2/book-library.md:6
msgid ""
@ -7357,13 +7373,13 @@ msgstr ""
msgid ""
"`String::new` returns a new empty string, use `String::with_capacity` when "
"you know how much data you want to push to the string."
msgstr ""
msgstr "“String::new”会返回一个新的空字符串,如果您知道自己想要推送到字符串的数据量,请使用“String::with_capacity”。"
#: src/std/string.md:31
msgid ""
"`String::len` returns the size of the `String` in bytes (which can be "
"different from its length in characters)."
msgstr ""
msgstr "“String::len”会返回“String”的大小(以字节为单位,可能不同于以字符为单位的长度)。"
#: src/std/string.md:32
msgid ""
@ -7372,51 +7388,52 @@ msgid ""
"to [grapheme "
"clusters](https://docs.rs/unicode-segmentation/latest/unicode_segmentation/struct.Graphemes.html)."
msgstr ""
"“String::chars”会针对实际字符返回一个迭代器。请注意,由于[字素簇](https://docs.rs/unicode-segmentation/latest/unicode_segmentation/struct.Graphemes.html),“char”可能与人们所认为的“字符”有所不同。"
#: src/std/string.md:33
msgid ""
"When people refer to strings they could either be talking about `&str` or "
"`String`."
msgstr ""
msgstr "当人们提到字符串时,可能是指“&str”或“String”。"
#: src/std/string.md:34
msgid ""
"When a type implements `Deref<Target = T>`, the compiler will let you "
"transparently call methods from `T`."
msgstr ""
msgstr "当某个类型实现“Deref\\<Target = T>”时,编译器会让您以公开透明方式从“T”调用方法。"
#: src/std/string.md:35
msgid ""
"`String` implements `Deref<Target = str>` which transparently gives it "
"access to `str`'s methods."
msgstr ""
msgstr "“String”会实现“Deref\\<Target = str>”,后者可公开透明地授予其访问“str”方法的权限。"
#: src/std/string.md:36
msgid "Write and compare `let s3 = s1.deref();` and `let s3 = &*s1`;."
msgstr ""
msgstr "写下并比较“let s3 = s1.deref();”和“let s3 = &\\*s1;”。"
#: src/std/string.md:37
msgid ""
"`String` is implemented as a wrapper around a vector of bytes, many of the "
"operations you see supported on vectors are also supported on `String`, but "
"with some extra guarantees."
msgstr ""
msgstr "“String”是作为字节矢量的封装容器实现的,矢量上支持的许多操作在“String”上也受支持,但有一些额外保证。"
#: src/std/string.md:38
msgid "Compare the different ways to index a `String`:"
msgstr ""
msgstr "比较将“String”编入索引的不同方式:"
#: src/std/string.md:39
msgid ""
"To a character by using `s3.chars().nth(i).unwrap()` where `i` is in-bound, "
"out-of-bounds."
msgstr ""
msgstr "使用“s3.chars().nth(i).unwrap()”转换为字符,其中“i”代表是否出界。"
#: src/std/string.md:40
msgid ""
"To a substring by using `s3[0..4]`, where that slice is on character "
"boundaries or not."
msgstr ""
msgstr "通过使用“s3\\[0..4\\]”转换为子字符串,其中该 Slice 在或不在字符边界上。"
#: src/std/vec.md:1
msgid "`Vec`"
@ -7472,19 +7489,24 @@ msgid ""
"it contains is stored on the heap. This means the amount of data doesn't "
"need to be known at compile time. It can grow or shrink at runtime."
msgstr ""
"“Vec”以及“String”和“HashMap”都是一种集合。它包含的数据会存储在堆上。这意味着在编译时不需要知道数据量。它可以在运行时增大或缩小。"
#: src/std/vec.md:40
#, fuzzy
msgid ""
"Notice how `Vec<T>` is a generic type too, but you don't have to specify `T` "
"explicitly. As always with Rust type inference, the `T` was established "
"during the first `push` call."
msgstr ""
"请注意,“Vec\n"
"\n"
"”也是一种泛型,但您不必明确指定“T”。和往常的 Rust 类别推断一样,系统会在第一次“push”调用期间建立“T”。"
#: src/std/vec.md:42
msgid ""
"`vec![...]` is a canonical macro to use instead of `Vec::new()` and it "
"supports adding initial elements to the vector."
msgstr ""
msgstr "“vec![...\\]”是用来代替“Vec::new()”的规范化宏,它支持向矢量添加初始元素。"
#: src/std/vec.md:44
msgid ""
@ -7492,12 +7514,14 @@ msgid ""
"Alternatively, using `get` will return an `Option`. The `pop` function will "
"remove the last element."
msgstr ""
"如需将矢量编入索引,您可以使用“\\[’ ‘\\]”方法,但如果超出边界,矢量将会 "
"panic。此外,使用“get”将返回“Option”。“pop”函数会移除最后一个元素。"
#: src/std/vec.md:46
msgid ""
"Show iterating over a vector and mutating the value: `for e in &mut v { *e "
"+= 50; }`"
msgstr ""
msgstr "介绍如何迭代矢量并更改它的值:“for e in &mut v { \\*e += 50; }”"
#: src/std/hashmap.md:1
#: src/bare-metal/no_std.md:46
@ -7549,7 +7573,7 @@ msgstr ""
#: src/std/hashmap.md:38
msgid ""
"`HashMap` is not defined in the prelude and needs to be brought into scope."
msgstr ""
msgstr "“HashMap”未在序言中定义,因此需要纳入范围中。"
#: src/std/hashmap.md:39
msgid ""
@ -7557,6 +7581,7 @@ msgid ""
"hashmap and if not return an alternative value. The second line will insert "
"the alternative value in the hashmap if the book is not found."
msgstr ""
"请尝试使用以下代码行。第一行将查看图书是否在 hashmap 中;如果不在,则返回替代值。如果未找到图书,第二行会在 hashmap 中插入替代值。"
#: src/std/hashmap.md:41
msgid ""
@ -7572,7 +7597,7 @@ msgstr ""
#: src/std/hashmap.md:49
msgid "Unlike `vec!`, there is unfortunately no standard `hashmap!` macro."
msgstr ""
msgstr "遗憾的是,与“vec!”不同,不存在标准的“hashmap!”宏。"
#: src/std/hashmap.md:50
msgid ""
@ -7580,6 +7605,8 @@ msgid ""
"N]>`](https://doc.rust-lang.org/std/collections/hash_map/struct.HashMap.html#impl-From%3C%5B(K,+V);+N%5D%3E-for-HashMap%3CK,+V,+RandomState%3E), "
"which allows us to easily initialize a hash map from a literal array:"
msgstr ""
"不过,从 Rust 1.56 开始,HashMap 实现了[“From\\<\\[(K, V); "
"N\\]\\>”](https://doc.rust-lang.org/std/collections/hash_map/struct.HashMap.html#impl-From%3C%5B(K,+V);+N%5D%3E-for-HashMap%3CK,+V,+RandomState%3E),让我们能够轻松地从字面量数组初始化哈希映射:"
#: src/std/hashmap.md:52
msgid ""
@ -7595,7 +7622,7 @@ msgstr ""
msgid ""
"Alternatively HashMap can be built from any `Iterator` which yields "
"key-value tuples."
msgstr ""
msgstr "或者,HashMap 也可以基于任何可生成键-值元组的“Iterator”进行构建。"
#: src/std/hashmap.md:60
msgid ""
@ -7603,12 +7630,14 @@ msgid ""
"examples easier. Using references in collections can, of course, be done, "
"but it can lead into complications with the borrow checker."
msgstr ""
"我们要展示“HashMap\\<String, "
"i32>”,避免将“&str”用作键,以便简化示例。当然,可以在集合中使用引用,但可能会导致借用检查器出现复杂问题。"
#: src/std/hashmap.md:62
msgid ""
"Try removing `to_string()` from the example above and see if it still "
"compiles. Where do you think we might run into issues?"
msgstr ""
msgstr "尝试从上述示例中移除“to_string()”,看看它是否仍可编译。您认为我们可能会在哪些方面遇到问题?"
#: src/std/hashmap.md:64
msgid ""
@ -7617,6 +7646,8 @@ msgid ""
"the Rust docs. Show students the docs for this type, and the helpful link "
"back to the `keys` method."
msgstr ""
"此类型具有几种特定于方法的返回值类型,例如“std::collections::hash_map::Keys”。这些类型通常会出现在 Rust "
"文档的搜索结果中。向学员展示此类型的文档,以及指向“keys”方法的实用链接。"
#: src/std/box.md:1
msgid "`Box`"
@ -7838,7 +7869,7 @@ msgstr "`Rc` 的计数可确保只要有引用,内含的值就会保持有效
#: src/std/rc.md:30
msgid "`Rc` in Rust is like `std::shared_ptr` in C++."
msgstr ""
msgstr "Rust 中的“Rc”与 C++ 中的“std::shared_ptr”类似。"
#: src/std/rc.md:31
msgid ""
@ -7866,9 +7897,8 @@ msgid ""
msgstr "`Rc::downgrade` 会向您提供 _弱引用计数_ 对象, 以便创建之后会被适当舍弃的周期(可能会与 `RefCell` 组合)。"
#: src/std/cell.md:1
#, fuzzy
msgid "`Cell` and `RefCell`"
msgstr "Cell/RefCell"
msgstr "“Cell”和“RefCell”"
#: src/std/cell.md:3
#, fuzzy
@ -7888,6 +7918,8 @@ msgid ""
"values. More complex interior types typically use `RefCell`, which tracks "
"shared and exclusive references at runtime and panics if they are misused."
msgstr ""
"“Cell”通常用于简单类型,因为它需要复制或移动值。更复杂的内部类型通常使用“RefCell”,它会在运行时跟踪已共享和专有的引用,并在这些引用被滥用时 "
"panic。"
#: src/std/cell.md:12
msgid ""
@ -7933,18 +7965,19 @@ msgid ""
"This is safe because there's always one, un-referenced value in the cell, "
"but it's not ergonomic."
msgstr ""
"在此示例中,如果我们使用的是“Cell”而非“RefCell”,则必须将“Node”从“Rc”中移出以推送子项,然后再将其移回原位。这是安全的做法,因为单元格中总是有一个未引用的值,但这不符合人体工程学。"
#: src/std/cell.md:48
msgid ""
"To do anything with a Node, you must call a `RefCell` method, usually "
"`borrow` or `borrow_mut`."
msgstr ""
msgstr "如需使用 Node 执行任何操作,您必须调用“RefCell”方法,通常为“borrow”或“borrow_mut”。"
#: src/std/cell.md:49
msgid ""
"Demonstrate that reference loops can be created by adding `root` to "
"`subtree.children` (don't try to print it!)."
msgstr ""
msgstr "演示可以通过向“subtree.children”添加“root”来创建引用循环(不要尝试输出它!)。"
#: src/std/cell.md:50
msgid ""
@ -7953,14 +7986,17 @@ msgid ""
"the presence of the reference loop, with `thread 'main' panicked at 'already "
"borrowed: BorrowMutError'`."
msgstr ""
"为了演示运行时 panic,请添加一个会递增“self.value”并以相同方法调用其子项的“fn inc(&mut "
"self)”。如果存在引用循环,就会 panic,并且“thread”“main”会因“already borrowed: "
"BorrowMutError”而 panic。"
#: src/modules.md:3
msgid "We have seen how `impl` blocks let us namespace functions to a type."
msgstr ""
msgstr "我们已看了“impl”块如何让我们将函数的命名空间建为一种类型。"
#: src/modules.md:5
msgid "Similarly, `mod` lets us namespace types and functions:"
msgstr ""
msgstr "同样,“mod”让我们可为类型和函数建立命名空间:"
#: src/modules.md:7
msgid ""
@ -7988,35 +8024,35 @@ msgstr ""
msgid ""
"Packages provide functionality and include a `Cargo.toml` file that "
"describes how to build a bundle of 1+ crates."
msgstr ""
msgstr "包提供功能,并包含一个描述如何构建包含 1 个以上 crate 的捆绑包的“Cargo.toml”文件。"
#: src/modules.md:29
msgid ""
"Crates are a tree of modules, where a binary crate creates an executable and "
"a library crate compiles to a library."
msgstr ""
msgstr "crate 是一种模块树,其中的二进制 crate 会创建一个可执行文件,而库 crate 会编译为库。"
#: src/modules.md:30
msgid "Modules define organization, scope, and are the focus of this section."
msgstr ""
msgstr "模块定义了组织和范围,并且是本部分的重点。"
#: src/modules/visibility.md:3
msgid "Modules are a privacy boundary:"
msgstr ""
msgstr "模块是一种隐私边界:"
#: src/modules/visibility.md:5
msgid "Module items are private by default (hides implementation details)."
msgstr ""
msgstr "默认情况下,模块项是私有的(隐藏实现详情)。"
#: src/modules/visibility.md:6
msgid "Parent and sibling items are always visible."
msgstr ""
msgstr "父项和同级子项始终可见。"
#: src/modules/visibility.md:7
msgid ""
"In other words, if an item is visible in module `foo`, it's visible in all "
"the descendants of `foo`."
msgstr ""
msgstr "换言之,如果某个项在模块“foo”中可见,那么该项在“foo”的所有后代中均可见。"
#: src/modules/visibility.md:10
msgid ""
@ -8050,72 +8086,74 @@ msgstr ""
#: src/modules/visibility.md:39
msgid "Use the `pub` keyword to make modules public."
msgstr ""
msgstr "使用“pub”关键字将模块设为公开。"
#: src/modules/visibility.md:41
msgid ""
"Additionally, there are advanced `pub(...)` specifiers to restrict the scope "
"of public visibility."
msgstr ""
msgstr "此外,您还可以使用高级“pub(...)”说明符来限制公开可见的范围。"
#: src/modules/visibility.md:43
msgid ""
"See the [Rust "
"Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html#pubin-path-pubcrate-pubsuper-and-pubself)."
msgstr ""
"请参阅 [Rust "
"参考](https://doc.rust-lang.org/reference/visibility-and-privacy.html#pubin-path-pubcrate-pubsuper-and-pubself)。"
#: src/modules/visibility.md:44
msgid "Configuring `pub(crate)` visibility is a common pattern."
msgstr ""
msgstr "配置“pub(crate)”可见性是一种常见模式。"
#: src/modules/visibility.md:45
msgid "Less commonly, you can give visibility to a specific path."
msgstr ""
msgstr "您可以为特定路径授予可见性,这种情况不太常见。"
#: src/modules/visibility.md:46
msgid ""
"In any case, visibility must be granted to an ancestor module (and all of "
"its descendants)."
msgstr ""
msgstr "在任何情况下,都必须向祖先模块(及其所有后代)授予可见性。"
#: src/modules/paths.md:3
msgid "Paths are resolved as follows:"
msgstr ""
msgstr "路径解析如下:"
#: src/modules/paths.md:5
msgid "As a relative path:"
msgstr ""
msgstr "作为相对路径:"
#: src/modules/paths.md:6
msgid "`foo` or `self::foo` refers to `foo` in the current module,"
msgstr ""
msgstr "“foo”或“self::foo”是指当前模块中的“foo”,"
#: src/modules/paths.md:7
msgid "`super::foo` refers to `foo` in the parent module."
msgstr ""
msgstr "“super::foo”是指父模块中的“foo”。"
#: src/modules/paths.md:9
msgid "As an absolute path:"
msgstr ""
msgstr "作为绝对路径:"
#: src/modules/paths.md:10
msgid "`crate::foo` refers to `foo` in the root of the current crate,"
msgstr ""
msgstr "“crate::foo”是指当前 crate 的根中的“foo”,"
#: src/modules/paths.md:11
msgid "`bar::foo` refers to `foo` in the `bar` crate."
msgstr ""
msgstr "“bar::foo”是指“bar”crate 中的“foo”。"
#: src/modules/paths.md:13
msgid ""
"A module can bring symbols from another module into scope with `use`. You "
"will typically see something like this at the top of each module:"
msgstr ""
msgstr "一个模块可以使用“use”将另一个模块的符号全部纳入。您通常在每个模块的顶部会看到如下内容:"
#: src/modules/filesystem.md:3
msgid ""
"Omitting the module content will tell Rust to look for it in another file:"
msgstr ""
msgstr "如果省略模块内容,则会指示 Rust 在另一个文件中查找:"
#: src/modules/filesystem.md:9
msgid ""
@ -8123,25 +8161,27 @@ msgid ""
"`src/garden.rs`. Similarly, a `garden::vegetables` module can be found at "
"`src/garden/vegetables.rs`."
msgstr ""
"这会告知 Rust "
"可以在“src/garden.rs”中找到“garden”模块内容。同样,您可以在“src/garden/vegetables.rs”中找到“garden::vegetables”模块。"
#: src/modules/filesystem.md:12
msgid "The `crate` root is in:"
msgstr ""
msgstr "“crate”根目录位于:"
#: src/modules/filesystem.md:14
msgid "`src/lib.rs` (for a library crate)"
msgstr ""
msgstr "“src/lib.rs”(对于库 crate)"
#: src/modules/filesystem.md:15
msgid "`src/main.rs` (for a binary crate)"
msgstr ""
msgstr "“src/main.rs”(对于二进制文件 crate)"
#: src/modules/filesystem.md:17
msgid ""
"Modules defined in files can be documented, too, using \"inner doc "
"comments\". These document the item that contains them -- in this case, a "
"module."
msgstr ""
msgstr "也可以使用“内部文档注释”对文件中定义的模块进行记录。这些用于记录包含它们的项(在本例中为模块)。"
#: src/modules/filesystem.md:20
msgid ""
@ -8167,23 +8207,25 @@ msgid ""
"Before Rust 2018, modules needed to be located at `module/mod.rs` instead of "
"`module.rs`, and this is still a working alternative for editions after 2018."
msgstr ""
"在 Rust 2018 之前的版本中,模块需要位于“module/mod.rs”而非“module.rs”中,对于 2018 "
"年之后的版本而言,这仍是有效的替代方案。"
#: src/modules/filesystem.md:39
msgid ""
"The main reason to introduce `filename.rs` as alternative to "
"`filename/mod.rs` was because many files named `mod.rs` can be hard to "
"distinguish in IDEs."
msgstr ""
msgstr "引入“filename.rs”来替代“filename/mod.rs”的主要原因是,许多名为“mod.rs”的文件在 IDE 中可能难以区分。"
#: src/modules/filesystem.md:42
msgid "Deeper nesting can use folders, even if the main module is a file:"
msgstr ""
msgstr "即使主模块是文件,更深层的嵌套也可以使用文件夹:"
#: src/modules/filesystem.md:52
msgid ""
"The place rust will look for modules can be changed with a compiler "
"directive:"
msgstr ""
msgstr "Rust 寻找模块的位置可通过编译器指令更改:"
#: src/modules/filesystem.md:54
msgid ""
@ -8197,7 +8239,7 @@ msgstr ""
msgid ""
"This is useful, for example, if you would like to place tests for a module "
"in a file named `some_module_test.rs`, similar to the convention in Go."
msgstr ""
msgstr "例如,如果您想将某个模块的测试放在名为“some_module_test.rs”的文件中(类似于 Go 中的惯例),这样做很有用。"
#: src/exercises/day-2/afternoon.md:1
msgid "Day 2: Afternoon Exercises"
@ -8214,22 +8256,25 @@ msgid ""
"[`IntoIterator`](https://doc.rust-lang.org/std/iter/trait.IntoIterator.html) "
"traits."
msgstr ""
"Rust 的所有权模式会影响许多 "
"API。例如,[“Iterator”](https://doc.rust-lang.org/std/iter/trait.Iterator.html)和[“IntoIterator”](https://doc.rust-lang.org/std/iter/trait.IntoIterator.html) "
"trait。"
#: src/exercises/day-2/iterators-and-ownership.md:8
#: src/bare-metal/no_std.md:28
msgid "`Iterator`"
msgstr ""
msgstr "“Iterator”"
#: src/exercises/day-2/iterators-and-ownership.md:10
msgid ""
"Traits are like interfaces: they describe behavior (methods) for a type. The "
"`Iterator` trait simply says that you can call `next` until you get `None` "
"back:"
msgstr ""
msgstr "trait 类似于接口:它们描述某类型的行为(方法)。“Iterator”trait 只是告知您可以调用“next”,直到返回“None”:"
#: src/exercises/day-2/iterators-and-ownership.md:20
msgid "You use this trait like this:"
msgstr ""
msgstr "您可以按如下方式使用此 trait:"
#: src/exercises/day-2/iterators-and-ownership.md:22
msgid ""
@ -8248,7 +8293,7 @@ msgstr ""
#: src/exercises/day-2/iterators-and-ownership.md:34
msgid "What is the type returned by the iterator? Test your answer here:"
msgstr ""
msgstr "迭代器返回的类型是什么?请在此测试您的答案:"
#: src/exercises/day-2/iterators-and-ownership.md:36
msgid ""
@ -8265,42 +8310,46 @@ msgstr ""
#: src/exercises/day-2/iterators-and-ownership.md:46
msgid "Why is this type used?"
msgstr ""
msgstr "为什么要使用此类型?"
#: src/exercises/day-2/iterators-and-ownership.md:48
msgid "`IntoIterator`"
msgstr ""
msgstr "“IntoIterator”"
#: src/exercises/day-2/iterators-and-ownership.md:50
msgid ""
"The `Iterator` trait tells you how to _iterate_ once you have created an "
"iterator. The related trait `IntoIterator` tells you how to create the "
"iterator:"
msgstr ""
msgstr "“Iterator”trait会告知您在创建迭代器后如何进行迭代。相关 trait“IntoIterator”会告知您如何创建迭代器:"
#: src/exercises/day-2/iterators-and-ownership.md:62
msgid ""
"The syntax here means that every implementation of `IntoIterator` must "
"declare two types:"
msgstr ""
msgstr "这里的语法表示,“IntoIterator”的每个实现都必须声明两种类型:"
#: src/exercises/day-2/iterators-and-ownership.md:65
msgid "`Item`: the type we iterate over, such as `i8`,"
msgstr ""
msgstr "“Item”:我们迭代的类型,例如“i8”,"
#: src/exercises/day-2/iterators-and-ownership.md:66
msgid "`IntoIter`: the `Iterator` type returned by the `into_iter` method."
msgstr ""
msgstr "“IntoIter”:“into_iter”方法返回的“Iterator”类型。"
#: src/exercises/day-2/iterators-and-ownership.md:68
#, fuzzy
msgid ""
"Note that `IntoIter` and `Item` are linked: the iterator must have the same "
"`Item` type, which means that it returns `Option<Item>`"
msgstr ""
"请注意,“IntoIter”和“Item”已关联:迭代器必须具有相同的“Item”类型,这意味着它会返回“Option\n"
"\n"
"”"
#: src/exercises/day-2/iterators-and-ownership.md:71
msgid "Like before, what is the type returned by the iterator?"
msgstr ""
msgstr "和之前一样,迭代器返回的类型是什么?"
#: src/exercises/day-2/iterators-and-ownership.md:73
msgid ""
@ -8318,7 +8367,7 @@ msgstr ""
#: src/exercises/day-2/iterators-and-ownership.md:83
msgid "`for` Loops"
msgstr ""
msgstr "“for”循环"
#: src/exercises/day-2/iterators-and-ownership.md:85
msgid ""
@ -8326,6 +8375,7 @@ msgid ""
"loops. They call `into_iter()` on an expression and iterates over the "
"resulting iterator:"
msgstr ""
"现在,我们已了解了“Iterator”和“IntoIterator”,接下来可以构建“for”循环了。它们会针对表达式调用“into_iter()”,并对生成的迭代器进行迭代:"
#: src/exercises/day-2/iterators-and-ownership.md:89
msgid ""
@ -8347,9 +8397,10 @@ msgstr ""
#: src/exercises/day-2/iterators-and-ownership.md:103
msgid "What is the type of `word` in each loop?"
msgstr ""
msgstr "每个循环中的“word”是什么类型?"
#: src/exercises/day-2/iterators-and-ownership.md:105
#, fuzzy
msgid ""
"Experiment with the code above and then consult the documentation for [`impl "
"IntoIterator for "
@ -8358,6 +8409,12 @@ msgid ""
"Vec<T>`](https://doc.rust-lang.org/std/vec/struct.Vec.html#impl-IntoIterator-for-Vec%3CT,+A%3E) "
"to check your answers."
msgstr ""
"使用上方代码进行实验,然后参阅[“impl IntoIterator for &Vec\n"
"\n"
"”](https://doc.rust-lang.org/std/vec/struct.Vec.html#impl-IntoIterator-for-%26'a+Vec%3CT,+A%3E)和[“impl "
"IntoIterator for Vec\n"
"\n"
"”](https://doc.rust-lang.org/std/vec/struct.Vec.html#impl-IntoIterator-for-Vec%3CT,+A%3E)的相关文档来检查您的答案。"
#: src/exercises/day-2/strings-iterators.md:3
msgid ""
@ -8366,12 +8423,14 @@ msgid ""
"against _request paths_. The path prefixes can contain a wildcard character "
"which matches a full segment. See the unit tests below."
msgstr ""
"在本练习中,您将实现 Web "
"服务器的路由组件。服务器配置有多个路径前缀,这些前缀与请求路径匹配。路径前缀可以包含与完整段匹配的通配符。请参阅下面的单元测试。"
#: src/exercises/day-2/strings-iterators.md:8
msgid ""
"Copy the following code to <https://play.rust-lang.org/> and make the tests "
"pass. Try avoiding allocating a `Vec` for your intermediate results:"
msgstr ""
msgstr "将以下代码复制到 <https://play.rust-lang.org/>,然后设法通过测试。请尽量避免为中间结果分配“Vec”:"
#: src/exercises/day-2/strings-iterators.md:12
msgid ""