msgid ""
msgstr ""
"Project-Id-Version: Comprehensive Rust 🦀\n"
"POT-Creation-Date: 2023-10-06T12:36:03-07:00\n"
"PO-Revision-Date: 2023-10-21 15:02+0800\n"
"Last-Translator: \n"
"Language-Team: Language zh-Hans\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.4\n"
#: src/SUMMARY.md:4 src/index.md:1
msgid "Welcome to Comprehensive Rust 🦀"
msgstr "欢迎来到 Comprehensive Rust 🦀"
#: src/SUMMARY.md:5 src/running-the-course.md:1
msgid "Running the Course"
msgstr "授课"
#: src/SUMMARY.md:6 src/running-the-course/course-structure.md:1
msgid "Course Structure"
msgstr "课程结构"
#: src/SUMMARY.md:7 src/running-the-course/keyboard-shortcuts.md:1
msgid "Keyboard Shortcuts"
msgstr "键盘快捷键"
#: src/SUMMARY.md:8 src/running-the-course/translations.md:1
msgid "Translations"
msgstr "翻译"
#: src/SUMMARY.md:9 src/cargo.md:1
msgid "Using Cargo"
msgstr "使用 Cargo"
#: src/SUMMARY.md:10
msgid "Rust Ecosystem"
msgstr "Rust 生态系统"
#: src/SUMMARY.md:11
msgid "Code Samples"
msgstr "代码示例"
#: src/SUMMARY.md:12
msgid "Running Cargo Locally"
msgstr "在本地运行 Cargo"
#: src/SUMMARY.md:15
msgid "Day 1: Morning"
msgstr "第一天:早上"
#: src/SUMMARY.md:19 src/SUMMARY.md:80 src/SUMMARY.md:135 src/SUMMARY.md:193
#: src/SUMMARY.md:219 src/SUMMARY.md:269
msgid "Welcome"
msgstr "欢迎"
#: src/SUMMARY.md:20 src/welcome-day-1/what-is-rust.md:1
msgid "What is Rust?"
msgstr "什么是 Rust?"
#: src/SUMMARY.md:21 src/hello-world.md:1
msgid "Hello World!"
msgstr "Hello World!"
#: src/SUMMARY.md:22 src/hello-world/small-example.md:1
msgid "Small Example"
msgstr "简短示例"
#: src/SUMMARY.md:23 src/why-rust.md:1
msgid "Why Rust?"
msgstr "为什么选择 Rust?"
#: src/SUMMARY.md:24 src/why-rust/an-example-in-c.md:1 src/credits.md:32
msgid "An Example in C"
msgstr "C语言示例"
#: src/SUMMARY.md:25 src/why-rust/compile-time.md:1
msgid "Compile Time Guarantees"
msgstr "编译期保障"
#: src/SUMMARY.md:26 src/why-rust/runtime.md:1
msgid "Runtime Guarantees"
msgstr "运行时保障"
#: src/SUMMARY.md:27 src/why-rust/modern.md:1
msgid "Modern Features"
msgstr "现代特性"
#: src/SUMMARY.md:28 src/basic-syntax.md:1
msgid "Basic Syntax"
msgstr "基本语法"
#: src/SUMMARY.md:29 src/basic-syntax/scalar-types.md:1
msgid "Scalar Types"
msgstr "标量类型"
#: src/SUMMARY.md:30 src/basic-syntax/compound-types.md:1
msgid "Compound Types"
msgstr "复合类型"
#: src/SUMMARY.md:31 src/basic-syntax/references.md:1
msgid "References"
msgstr "引用"
#: src/SUMMARY.md:32 src/basic-syntax/references-dangling.md:1
msgid "Dangling References"
msgstr "悬垂引用"
#: src/SUMMARY.md:33 src/basic-syntax/slices.md:1
msgid "Slices"
msgstr "切片"
#: src/SUMMARY.md:34
msgid "String vs str"
msgstr "String vs str"
#: src/SUMMARY.md:35 src/basic-syntax/functions.md:1
msgid "Functions"
msgstr "函数"
#: src/SUMMARY.md:36 src/basic-syntax/rustdoc.md:1
msgid "Rustdoc"
msgstr "Rustdoc"
#: src/SUMMARY.md:37 src/SUMMARY.md:103 src/basic-syntax/methods.md:1
#: src/methods.md:1
msgid "Methods"
msgstr "方法"
#: src/SUMMARY.md:38
msgid "Overloading"
msgstr "重载"
#: src/SUMMARY.md:39 src/SUMMARY.md:72 src/SUMMARY.md:106 src/SUMMARY.md:126
#: src/SUMMARY.md:155 src/SUMMARY.md:185 src/SUMMARY.md:212 src/SUMMARY.md:233
#: src/SUMMARY.md:261 src/SUMMARY.md:283 src/SUMMARY.md:304
#: src/exercises/android/morning.md:1 src/exercises/bare-metal/morning.md:1
#: src/exercises/bare-metal/afternoon.md:1
#: src/exercises/concurrency/morning.md:1
#: src/exercises/concurrency/afternoon.md:1
msgid "Exercises"
msgstr "习题"
#: src/SUMMARY.md:40 src/exercises/day-1/implicit-conversions.md:1
msgid "Implicit Conversions"
msgstr "隐式类型转换"
#: src/SUMMARY.md:41
msgid "Arrays and for Loops"
msgstr "数组与 for 循环"
#: src/SUMMARY.md:43
msgid "Day 1: Afternoon"
msgstr "第一天:下午"
#: src/SUMMARY.md:45 src/SUMMARY.md:296 src/control-flow.md:1
msgid "Control Flow"
msgstr "控制流"
#: src/SUMMARY.md:46 src/control-flow/blocks.md:1
msgid "Blocks"
msgstr "块"
#: src/SUMMARY.md:47
msgid "if expressions"
msgstr "if 表达式"
#: src/SUMMARY.md:48
msgid "for expressions"
msgstr "for 表达式"
#: src/SUMMARY.md:49
msgid "while expressions"
msgstr "while 表达式"
#: src/SUMMARY.md:50
msgid "break & continue"
msgstr "break & continue"
#: src/SUMMARY.md:51
msgid "loop expressions"
msgstr "loop 表达式"
#: src/SUMMARY.md:53 src/basic-syntax/variables.md:1
msgid "Variables"
msgstr "变量"
#: src/SUMMARY.md:54 src/basic-syntax/type-inference.md:1
msgid "Type Inference"
msgstr "类型推导"
#: src/SUMMARY.md:55
msgid "static & const"
msgstr "静态变量与常量"
#: src/SUMMARY.md:56 src/basic-syntax/scopes-shadowing.md:1
msgid "Scopes and Shadowing"
msgstr "作用域和遮蔽(Shadowing)"
#: src/SUMMARY.md:57 src/enums.md:1
msgid "Enums"
msgstr "枚举"
#: src/SUMMARY.md:58 src/enums/variant-payloads.md:1
msgid "Variant Payloads"
msgstr "变体载荷"
#: src/SUMMARY.md:59 src/enums/sizes.md:1
msgid "Enum Sizes"
msgstr "枚举大小"
#: src/SUMMARY.md:61 src/control-flow/novel.md:1
msgid "Novel Control Flow"
msgstr "新式控制流"
#: src/SUMMARY.md:62
msgid "if let expressions"
msgstr "if let 表达式"
#: src/SUMMARY.md:63
msgid "while let expressions"
msgstr "while let 表达式"
#: src/SUMMARY.md:64
msgid "match expressions"
msgstr "match 表达式"
#: src/SUMMARY.md:66 src/SUMMARY.md:74 src/pattern-matching.md:1
msgid "Pattern Matching"
msgstr "模式匹配"
#: src/SUMMARY.md:67 src/pattern-matching/destructuring-enums.md:1
msgid "Destructuring Enums"
msgstr "解构枚举"
#: src/SUMMARY.md:68 src/pattern-matching/destructuring-structs.md:1
msgid "Destructuring Structs"
msgstr "解构结构体"
#: src/SUMMARY.md:69 src/pattern-matching/destructuring-arrays.md:1
msgid "Destructuring Arrays"
msgstr "解构数组"
#: src/SUMMARY.md:70 src/pattern-matching/match-guards.md:1
msgid "Match Guards"
msgstr "匹配守卫"
#: src/SUMMARY.md:73 src/exercises/day-1/luhn.md:1
#: src/exercises/day-1/solutions-afternoon.md:3
msgid "Luhn Algorithm"
msgstr "卢恩算法"
#: src/SUMMARY.md:76
msgid "Day 2: Morning"
msgstr "第二天:上午"
#: src/SUMMARY.md:82 src/memory-management.md:1
msgid "Memory Management"
msgstr "内存管理"
#: src/SUMMARY.md:83
msgid "Stack vs Heap"
msgstr "栈 vs 堆"
#: src/SUMMARY.md:84
msgid "Stack Memory"
msgstr "栈内存"
#: src/SUMMARY.md:85 src/memory-management/manual.md:1
msgid "Manual Memory Management"
msgstr "手动内存管理"
#: src/SUMMARY.md:86 src/memory-management/scope-based.md:1
msgid "Scope-Based Memory Management"
msgstr "基于作用域的内存管理"
#: src/SUMMARY.md:87
msgid "Garbage Collection"
msgstr "垃圾回收"
#: src/SUMMARY.md:88
msgid "Rust Memory Management"
msgstr "Rust 内存管理"
#: src/SUMMARY.md:89 src/ownership.md:1
msgid "Ownership"
msgstr "所有权"
#: src/SUMMARY.md:90 src/ownership/move-semantics.md:1
msgid "Move Semantics"
msgstr "移动语义"
#: src/SUMMARY.md:91 src/ownership/moved-strings-rust.md:1
msgid "Moved Strings in Rust"
msgstr "Rust 中移动的字符串"
#: src/SUMMARY.md:92
msgid "Double Frees in Modern C++"
msgstr "现代 C++ 中的双重释放"
#: src/SUMMARY.md:93 src/ownership/moves-function-calls.md:1
msgid "Moves in Function Calls"
msgstr "函数调用中的移动"
#: src/SUMMARY.md:94 src/ownership/copy-clone.md:1
msgid "Copying and Cloning"
msgstr "复制和克隆"
#: src/SUMMARY.md:95 src/ownership/borrowing.md:1
msgid "Borrowing"
msgstr "借用"
#: src/SUMMARY.md:96 src/ownership/shared-unique-borrows.md:1
msgid "Shared and Unique Borrows"
msgstr "共享和唯一的借用"
#: src/SUMMARY.md:97 src/ownership/lifetimes.md:1
msgid "Lifetimes"
msgstr "生命周期"
#: src/SUMMARY.md:98 src/ownership/lifetimes-function-calls.md:1
msgid "Lifetimes in Function Calls"
msgstr "函数调用中的生命周期"
#: src/SUMMARY.md:99 src/ownership/lifetimes-data-structures.md:1
msgid "Lifetimes in Data Structures"
msgstr "数据结构中的生命周期"
#: src/SUMMARY.md:100 src/structs.md:1
msgid "Structs"
msgstr "结构体"
#: src/SUMMARY.md:101 src/structs/tuple-structs.md:1
msgid "Tuple Structs"
msgstr "元组结构体"
#: src/SUMMARY.md:102 src/structs/field-shorthand.md:1
msgid "Field Shorthand Syntax"
msgstr "字段简写语法"
#: src/SUMMARY.md:104 src/methods/receiver.md:1
msgid "Method Receiver"
msgstr "方法接收者"
#: src/SUMMARY.md:105 src/SUMMARY.md:167 src/SUMMARY.md:282
#: src/methods/example.md:1 src/concurrency/shared_state/example.md:1
msgid "Example"
msgstr "示例"
#: src/SUMMARY.md:107 src/exercises/day-2/book-library.md:1
msgid "Storing Books"
msgstr "书籍存储"
#: src/SUMMARY.md:108 src/exercises/day-2/health-statistics.md:1
#: src/exercises/day-2/solutions-morning.md:151
msgid "Health Statistics"
msgstr "健康统计"
#: src/SUMMARY.md:110
msgid "Day 2: Afternoon"
msgstr "第二天:下午"
#: src/SUMMARY.md:112 src/std.md:1
msgid "Standard Library"
msgstr "标准库"
#: src/SUMMARY.md:113
msgid "Option and Result"
msgstr "Option 和 Result"
#: src/SUMMARY.md:114 src/std/string.md:1
msgid "String"
msgstr "String"
#: src/SUMMARY.md:115
msgid "Vec"
msgstr "Vec"
#: src/SUMMARY.md:116
msgid "HashMap"
msgstr "哈希表"
#: src/SUMMARY.md:117
msgid "Box"
msgstr "Box"
#: src/SUMMARY.md:118
msgid "Recursive Data Types"
msgstr "递归数据类型"
#: src/SUMMARY.md:119 src/std/box-niche.md:1
msgid "Niche Optimization"
msgstr "小众优化"
#: src/SUMMARY.md:120
msgid "Rc"
msgstr "Rc"
#: src/SUMMARY.md:121
msgid "Cell/RefCell"
msgstr "Cell/RefCell"
#: src/SUMMARY.md:122 src/modules.md:1
msgid "Modules"
msgstr "模块"
#: src/SUMMARY.md:123 src/modules/visibility.md:1
msgid "Visibility"
msgstr "可见性"
#: src/SUMMARY.md:124 src/modules/paths.md:1
msgid "Paths"
msgstr "路径"
#: src/SUMMARY.md:125 src/modules/filesystem.md:1
msgid "Filesystem Hierarchy"
msgstr "文件系统层级结构"
#: src/SUMMARY.md:127 src/exercises/day-2/iterators-and-ownership.md:1
msgid "Iterators and Ownership"
msgstr "迭代器和所有权"
#: src/SUMMARY.md:128 src/exercises/day-2/strings-iterators.md:1
#: src/exercises/day-2/solutions-afternoon.md:3
msgid "Strings and Iterators"
msgstr "字符串和迭代器"
#: src/SUMMARY.md:131
msgid "Day 3: Morning"
msgstr "第三天:上午"
#: src/SUMMARY.md:136 src/generics.md:1
msgid "Generics"
msgstr "泛型"
#: src/SUMMARY.md:137 src/generics/data-types.md:1
msgid "Generic Data Types"
msgstr "通用数据类型"
#: src/SUMMARY.md:138 src/generics/methods.md:1
msgid "Generic Methods"
msgstr "泛型方法"
#: src/SUMMARY.md:139 src/generics/monomorphization.md:1
msgid "Monomorphization"
msgstr "单态化"
#: src/SUMMARY.md:140 src/traits.md:1
msgid "Traits"
msgstr "特征(Trait)"
#: src/SUMMARY.md:141 src/traits/trait-objects.md:1
msgid "Trait Objects"
msgstr "特征对象"
#: src/SUMMARY.md:142 src/traits/deriving-traits.md:1
msgid "Deriving Traits"
msgstr "派生特征"
#: src/SUMMARY.md:143 src/traits/default-methods.md:1
msgid "Default Methods"
msgstr "默认方法"
#: src/SUMMARY.md:144 src/traits/trait-bounds.md:1
msgid "Trait Bounds"
msgstr "特征边界"
#: src/SUMMARY.md:145
msgid "impl Trait"
msgstr "impl Trait"
#: src/SUMMARY.md:146 src/traits/important-traits.md:1
msgid "Important Traits"
msgstr "重要特征"
#: src/SUMMARY.md:147
msgid "Iterator"
msgstr "迭代器"
#: src/SUMMARY.md:148 src/traits/from-iterator.md:1
msgid "FromIterator"
msgstr "FromIterator"
#: src/SUMMARY.md:149
msgid "From and Into"
msgstr "From 和 Into"
#: src/SUMMARY.md:150
msgid "Read and Write"
msgstr "读取和写入"
#: src/SUMMARY.md:151
msgid "Drop"
msgstr "Drop"
#: src/SUMMARY.md:152
msgid "Default"
msgstr "Default"
#: src/SUMMARY.md:153
msgid "Operators: Add, Mul, ..."
msgstr "运算符:Add、Mul..."
#: src/SUMMARY.md:154
msgid "Closures: Fn, FnMut, FnOnce"
msgstr "闭包:Fn、FnMut、FnOnce"
#: src/SUMMARY.md:156
msgid "A Simple GUI Library"
msgstr "一个简单的 GUI 库"
#: src/SUMMARY.md:157 src/exercises/day-3/solutions-morning.md:142
msgid "Points and Polygons"
msgstr "点和多边形"
#: src/SUMMARY.md:159
msgid "Day 3: Afternoon"
msgstr "第三天:下午"
#: src/SUMMARY.md:161 src/error-handling.md:1
msgid "Error Handling"
msgstr "错误处理"
#: src/SUMMARY.md:162 src/error-handling/panics.md:1
msgid "Panics"
msgstr "Panics"
#: src/SUMMARY.md:163
msgid "Catching Stack Unwinding"
msgstr "捕获堆栈展开"
#: src/SUMMARY.md:164
msgid "Structured Error Handling"
msgstr "结构化错误处理"
#: src/SUMMARY.md:165
msgid "Propagating Errors with ?"
msgstr "使用 ? 传播错误"
#: src/SUMMARY.md:166 src/error-handling/converting-error-types.md:1
#: src/error-handling/converting-error-types-example.md:1
msgid "Converting Error Types"
msgstr "转换错误类型"
#: src/SUMMARY.md:168 src/error-handling/deriving-error-enums.md:1
msgid "Deriving Error Enums"
msgstr "派生错误枚举"
#: src/SUMMARY.md:169 src/error-handling/dynamic-errors.md:1
msgid "Dynamic Error Types"
msgstr "动态错误类型"
#: src/SUMMARY.md:170 src/error-handling/error-contexts.md:1
msgid "Adding Context to Errors"
msgstr "为错误添加背景信息"
#: src/SUMMARY.md:171 src/testing.md:1
msgid "Testing"
msgstr "测试"
#: src/SUMMARY.md:172 src/testing/unit-tests.md:1
msgid "Unit Tests"
msgstr "单元测试"
#: src/SUMMARY.md:173 src/testing/test-modules.md:1
msgid "Test Modules"
msgstr "测试模块"
#: src/SUMMARY.md:174 src/testing/doc-tests.md:1
msgid "Documentation Tests"
msgstr "文档测试"
#: src/SUMMARY.md:175 src/testing/integration-tests.md:1
msgid "Integration Tests"
msgstr "集成测试"
#: src/SUMMARY.md:176 src/bare-metal/useful-crates.md:1
msgid "Useful crates"
msgstr "实用 crate"
#: src/SUMMARY.md:177 src/unsafe.md:1
msgid "Unsafe Rust"
msgstr "不安全 Rust"
#: src/SUMMARY.md:178 src/unsafe/raw-pointers.md:1
msgid "Dereferencing Raw Pointers"
msgstr "解引用裸指针"
#: src/SUMMARY.md:179 src/unsafe/mutable-static-variables.md:1
msgid "Mutable Static Variables"
msgstr "可变的静态变量"
#: src/SUMMARY.md:180 src/unsafe/unions.md:1
msgid "Unions"
msgstr "联合体"
#: src/SUMMARY.md:181 src/unsafe/calling-unsafe-functions.md:1
msgid "Calling Unsafe Functions"
msgstr "调用 Unsafe 函数"
#: src/SUMMARY.md:182 src/unsafe/writing-unsafe-functions.md:1
msgid "Writing Unsafe Functions"
msgstr "编写 Unsafe 函数"
#: src/SUMMARY.md:183
msgid "Extern Functions"
msgstr "外部函数"
#: src/SUMMARY.md:184 src/unsafe/unsafe-traits.md:1
msgid "Implementing Unsafe Traits"
msgstr "实现 Unsafe Trait"
#: src/SUMMARY.md:186 src/exercises/day-3/safe-ffi-wrapper.md:1
#: src/exercises/day-3/solutions-afternoon.md:3
msgid "Safe FFI Wrapper"
msgstr "安全 FFI 封装容器"
#: src/SUMMARY.md:189 src/SUMMARY.md:259 src/bare-metal/android.md:1
msgid "Android"
msgstr "Android"
#: src/SUMMARY.md:194 src/android/setup.md:1
msgid "Setup"
msgstr "设置"
#: src/SUMMARY.md:195 src/android/build-rules.md:1
msgid "Build Rules"
msgstr "构建规则"
#: src/SUMMARY.md:196
msgid "Binary"
msgstr "可执行文件"
#: src/SUMMARY.md:197
msgid "Library"
msgstr "库"
#: src/SUMMARY.md:198 src/android/aidl.md:1
msgid "AIDL"
msgstr "AIDL"
#: src/SUMMARY.md:199
msgid "Interface"
msgstr "接口"
#: src/SUMMARY.md:200
msgid "Implementation"
msgstr "实现"
#: src/SUMMARY.md:201
msgid "Server"
msgstr "服务器"
#: src/SUMMARY.md:202 src/android/aidl/deploy.md:1
msgid "Deploy"
msgstr "部署"
#: src/SUMMARY.md:203
msgid "Client"
msgstr "客户端"
#: src/SUMMARY.md:204 src/android/aidl/changing.md:1
msgid "Changing API"
msgstr "更改 API"
#: src/SUMMARY.md:205 src/SUMMARY.md:249 src/android/logging.md:1
#: src/bare-metal/aps/logging.md:1
msgid "Logging"
msgstr "日志记录"
#: src/SUMMARY.md:206 src/android/interoperability.md:1
msgid "Interoperability"
msgstr "互操作性"
#: src/SUMMARY.md:207
msgid "With C"
msgstr "与 C 语言交互"
#: src/SUMMARY.md:208
msgid "Calling C with Bindgen"
msgstr "使用 Bindgen 调用 C 语言"
#: src/SUMMARY.md:209
msgid "Calling Rust from C"
msgstr "从 C 语言调用 Rust 语言"
#: src/SUMMARY.md:210 src/android/interoperability/cpp.md:1
msgid "With C++"
msgstr "与 C++ 交互"
#: src/SUMMARY.md:211
msgid "With Java"
msgstr "与 Java 交互"
#: src/SUMMARY.md:215
msgid "Bare Metal: Morning"
msgstr "裸金属:上午"
#: src/SUMMARY.md:220
msgid "no_std"
msgstr "no_std"
#: src/SUMMARY.md:221
msgid "A Minimal Example"
msgstr "最小示例"
#: src/SUMMARY.md:222
msgid "alloc"
msgstr "alloc"
#: src/SUMMARY.md:223 src/bare-metal/microcontrollers.md:1
msgid "Microcontrollers"
msgstr "微控制器"
#: src/SUMMARY.md:224 src/bare-metal/microcontrollers/mmio.md:1
msgid "Raw MMIO"
msgstr "原始 MMIO"
#: src/SUMMARY.md:225
msgid "PACs"
msgstr "PAC"
#: src/SUMMARY.md:226
msgid "HAL Crates"
msgstr "HAL crate"
#: src/SUMMARY.md:227
msgid "Board Support Crates"
msgstr "板级支持 Crate"
#: src/SUMMARY.md:228
msgid "The Type State Pattern"
msgstr "类型状态模式"
#: src/SUMMARY.md:229
#, fuzzy
msgid "embedded-hal"
msgstr "embedded-hal"
#: src/SUMMARY.md:230
msgid "probe-rs, cargo-embed"
msgstr "probe-rs、cargo-embed"
#: src/SUMMARY.md:231 src/bare-metal/microcontrollers/debugging.md:1
#, fuzzy
msgid "Debugging"
msgstr "调试"
#: src/SUMMARY.md:232 src/SUMMARY.md:252
msgid "Other Projects"
msgstr "其他项目"
#: src/SUMMARY.md:234 src/exercises/bare-metal/compass.md:1
#: src/exercises/bare-metal/solutions-morning.md:3
msgid "Compass"
msgstr "罗盘"
#: src/SUMMARY.md:236
msgid "Bare Metal: Afternoon"
msgstr "裸金属:下午"
#: src/SUMMARY.md:238
msgid "Application Processors"
msgstr "应用处理器"
#: src/SUMMARY.md:239 src/bare-metal/aps/entry-point.md:1
msgid "Getting Ready to Rust"
msgstr "准备使用 Rust"
#: src/SUMMARY.md:240
msgid "Inline Assembly"
msgstr "内联汇编"
#: src/SUMMARY.md:241
msgid "MMIO"
msgstr "MMIO"
#: src/SUMMARY.md:242
msgid "Let's Write a UART Driver"
msgstr "编写 UART 驱动程序"
#: src/SUMMARY.md:243
msgid "More Traits"
msgstr "更多 trait"
#: src/SUMMARY.md:244
msgid "A Better UART Driver"
msgstr "一个更好的 UART 驱动程序"
#: src/SUMMARY.md:245 src/bare-metal/aps/better-uart/bitflags.md:1
msgid "Bitflags"
msgstr "Bitflags"
#: src/SUMMARY.md:246
msgid "Multiple Registers"
msgstr "多个寄存器"
#: src/SUMMARY.md:247 src/bare-metal/aps/better-uart/driver.md:1
msgid "Driver"
msgstr "驱动程序"
#: src/SUMMARY.md:248 src/SUMMARY.md:250
msgid "Using It"
msgstr "开始使用"
#: src/SUMMARY.md:251 src/bare-metal/aps/exceptions.md:1
msgid "Exceptions"
msgstr "异常"
#: src/SUMMARY.md:253
msgid "Useful Crates"
msgstr "实用 crate"
#: src/SUMMARY.md:254
msgid "zerocopy"
msgstr "zerocopy"
#: src/SUMMARY.md:255
msgid "aarch64-paging"
msgstr "aarch64-paging"
#: src/SUMMARY.md:256
msgid "buddy_system_allocator"
msgstr "buddy_system_allocator"
#: src/SUMMARY.md:257
msgid "tinyvec"
msgstr "tinyvec"
#: src/SUMMARY.md:258
msgid "spin"
msgstr "转动"
#: src/SUMMARY.md:260 src/bare-metal/android/vmbase.md:1
msgid "vmbase"
msgstr "vmbase"
#: src/SUMMARY.md:262
msgid "RTC Driver"
msgstr "RTC驱动"
#: src/SUMMARY.md:265
msgid "Concurrency: Morning"
msgstr "并发编程:上午"
#: src/SUMMARY.md:270 src/concurrency/threads.md:1
msgid "Threads"
msgstr "线程"
#: src/SUMMARY.md:271 src/concurrency/scoped-threads.md:1
msgid "Scoped Threads"
msgstr "范围线程"
#: src/SUMMARY.md:272 src/concurrency/channels.md:1
msgid "Channels"
msgstr "通道"
#: src/SUMMARY.md:273 src/concurrency/channels/unbounded.md:1
msgid "Unbounded Channels"
msgstr "无界通道"
#: src/SUMMARY.md:274 src/concurrency/channels/bounded.md:1
msgid "Bounded Channels"
msgstr "有界通道"
#: src/SUMMARY.md:275
msgid "Send and Sync"
msgstr "Send 和 Sync"
#: src/SUMMARY.md:275
msgid "Send"
msgstr "Send"
#: src/SUMMARY.md:275
msgid "Sync"
msgstr "Sync"
#: src/SUMMARY.md:278 src/concurrency/send-sync/examples.md:1
msgid "Examples"
msgstr "示例"
#: src/SUMMARY.md:279 src/concurrency/shared_state.md:1
msgid "Shared State"
msgstr "共享状态"
#: src/SUMMARY.md:280
msgid "Arc"
msgstr "Arc"
#: src/SUMMARY.md:281
msgid "Mutex"
msgstr "Mutex"
#: src/SUMMARY.md:284 src/SUMMARY.md:305
#: src/exercises/concurrency/dining-philosophers.md:1
#: src/exercises/concurrency/solutions-morning.md:3
msgid "Dining Philosophers"
msgstr "哲学家就餐问题 (Dining philosophers problem)"
#: src/SUMMARY.md:285 src/exercises/concurrency/link-checker.md:1
msgid "Multi-threaded Link Checker"
msgstr "多线程链接检查器"
#: src/SUMMARY.md:287
msgid "Concurrency: Afternoon"
msgstr "并发:下午"
#: src/SUMMARY.md:289
msgid "Async Basics"
msgstr "异步基础"
#: src/SUMMARY.md:290
msgid "async/await"
msgstr "async/await"
#: src/SUMMARY.md:291 src/async/futures.md:1
msgid "Futures"
msgstr "Futures"
#: src/SUMMARY.md:292 src/async/runtimes.md:1
msgid "Runtimes"
msgstr "Runtimes"
#: src/SUMMARY.md:293 src/async/runtimes/tokio.md:1
msgid "Tokio"
msgstr "Tokio"
#: src/SUMMARY.md:294 src/exercises/concurrency/link-checker.md:126
#: src/async/tasks.md:1 src/exercises/concurrency/chat-app.md:143
msgid "Tasks"
msgstr "任务"
#: src/SUMMARY.md:295 src/async/channels.md:1
msgid "Async Channels"
msgstr "异步通道"
#: src/SUMMARY.md:297 src/async/control-flow/join.md:1
msgid "Join"
msgstr "加入"
#: src/SUMMARY.md:298 src/async/control-flow/select.md:1
msgid "Select"
msgstr "选择"
#: src/SUMMARY.md:299
msgid "Pitfalls"
msgstr "误区"
#: src/SUMMARY.md:300
msgid "Blocking the Executor"
msgstr "屏蔽执行器"
#: src/SUMMARY.md:301 src/async/pitfalls/pin.md:1
msgid "Pin"
msgstr "固定"
#: src/SUMMARY.md:302 src/async/pitfalls/async-traits.md:1
msgid "Async Traits"
msgstr "异步特质"
#: src/SUMMARY.md:303 src/async/pitfalls/cancellation.md:1
msgid "Cancellation"
msgstr "消除"
#: src/SUMMARY.md:306 src/exercises/concurrency/chat-app.md:1
#: src/exercises/concurrency/solutions-afternoon.md:95
msgid "Broadcast Chat Application"
msgstr "广播聊天应用程序"
#: src/SUMMARY.md:309
msgid "Final Words"
msgstr "结束语"
#: src/SUMMARY.md:313 src/thanks.md:1
msgid "Thanks!"
msgstr "谢谢!"
#: src/SUMMARY.md:314 src/glossary.md:1
msgid "Glossary"
msgstr "词汇表"
#: src/SUMMARY.md:315
msgid "Other Resources"
msgstr "其他资源"
#: src/SUMMARY.md:316 src/credits.md:1
msgid "Credits"
msgstr "鸣谢"
#: src/SUMMARY.md:319 src/exercises/solutions.md:1
msgid "Solutions"
msgstr "解答"
#: src/SUMMARY.md:324
msgid "Day 1 Morning"
msgstr "第一天上午"
#: src/SUMMARY.md:325
msgid "Day 1 Afternoon"
msgstr "第一天下午"
#: src/SUMMARY.md:326
msgid "Day 2 Morning"
msgstr "第二天上午"
#: src/SUMMARY.md:327
msgid "Day 2 Afternoon"
msgstr "第二天下午"
#: src/SUMMARY.md:328
msgid "Day 3 Morning"
msgstr "第三天上午"
#: src/SUMMARY.md:329
msgid "Day 3 Afternoon"
msgstr "第三天下午"
#: src/SUMMARY.md:330
msgid "Bare Metal Rust Morning"
msgstr "嵌入式 Rust:入门篇"
#: src/SUMMARY.md:331 src/exercises/bare-metal/solutions-afternoon.md:1
msgid "Bare Metal Rust Afternoon"
msgstr "嵌入式 Rust:进阶篇"
#: src/SUMMARY.md:332
msgid "Concurrency Morning"
msgstr "并发编程:入门篇"
#: src/SUMMARY.md:333
msgid "Concurrency Afternoon"
msgstr "并发编程:进阶篇"
#: src/index.md:3
#, fuzzy
msgid ""
"[![Build workflow](https://img.shields.io/github/actions/workflow/status/"
"google/comprehensive-rust/build.yml?style=flat-square)](https://github.com/"
"google/comprehensive-rust/actions/workflows/build.yml?query=branch%3Amain) [!"
"[GitHub contributors](https://img.shields.io/github/contributors/google/"
"comprehensive-rust?style=flat-square)](https://github.com/google/"
"comprehensive-rust/graphs/contributors) [![GitHub stars](https://img.shields."
"io/github/stars/google/comprehensive-rust?style=flat-square)](https://github."
"com/google/comprehensive-rust/stargazers)"
msgstr ""
"[![构建工作流](https://img.shields.io/github/actions/workflow/status/google/"
"comprehensive-rust/build.yml?style=flat-square)](https://github.com/google/"
"comprehensive-rust/actions/workflows/build.yml?query=branch%3Amain) [!"
"[GitHub 贡献者](https://img.shields.io/github/contributors/google/"
"comprehensive-rust?style=flat-square)](https://github.com/google/"
"comprehensive-rust/graphs/contributors)"
#: src/index.md:7
msgid ""
"This is a free Rust course developed by the Android team at Google. The "
"course covers the full spectrum of Rust, from basic syntax to advanced "
"topics like generics and error handling."
msgstr ""
"这是由 Android 团队开发的免费 Rust 课程。该课程涵盖了 Rust 的全部范围,从基本"
"语法到高级主题如泛型和错误处理。"
#: src/index.md:11
msgid ""
"The latest version of the course can be found at . If you are reading somewhere else, please check there "
"for updates."
msgstr ""
"如需查看课程的最新版本,请访问 。如果你是在其他地方阅读,请查看此网址了解是否有更新。"
#: src/index.md:15
msgid ""
"The goal of the course is to teach you Rust. We assume you don't know "
"anything about Rust and hope to:"
msgstr "本课程的目标是教授你 Rust。我们假设你对 Rust 一无所知,并希望能够:"
#: src/index.md:18
msgid "Give you a comprehensive understanding of the Rust syntax and language."
msgstr "帮助你全面理解 Rust 的语法和语言。"
#: src/index.md:19
msgid "Enable you to modify existing programs and write new programs in Rust."
msgstr "使你能够修改现有的程序并用 Rust 编写新程序。"
#: src/index.md:20
msgid "Show you common Rust idioms."
msgstr "展示常见的 Rust 习语。"
#: src/index.md:22
msgid "We call the first three course days Rust Fundamentals."
msgstr "我们将前三天的课程称为“Rust 基础知识”。"
#: src/index.md:24
msgid ""
"Building on this, you're invited to dive into one or more specialized topics:"
msgstr "在此基础上,你可以选择深入学习一个或多个专门的主题:"
#: src/index.md:26
msgid ""
"[Android](android.md): a half-day course on using Rust for Android platform "
"development (AOSP). This includes interoperability with C, C++, and Java."
msgstr ""
"[Android](android.md):为期半天的课程,介绍如何在 Android 平台开发中使用 Rust"
"(AOSP)。课程内容包括与 C、C++ 和 Java 的互操作性。"
#: src/index.md:28
msgid ""
"[Bare-metal](bare-metal.md): a whole-day class on using Rust for bare-metal "
"(embedded) development. Both microcontrollers and application processors are "
"covered."
msgstr ""
"[Bare-metal](bare-metal.md):为期一天的课程,介绍如何使用 Rust 进行裸机(嵌入"
"式)开发。课程内容涵盖微控制器和应用处理器。"
#: src/index.md:31
msgid ""
"[Concurrency](concurrency.md): a whole-day class on concurrency in Rust. We "
"cover both classical concurrency (preemptively scheduling using threads and "
"mutexes) and async/await concurrency (cooperative multitasking using "
"futures)."
msgstr ""
"[并发](concurrency.md):为期一天的课程,介绍 Rust 中的并发性。我们将涵盖传统"
"并发(使用线程和互斥锁进行抢占式调度)和 async/await 并发(使用 futures 进行"
"协作式多任务处理)。"
#: src/index.md:37
msgid "Non-Goals"
msgstr "非目标"
#: src/index.md:39
msgid ""
"Rust is a large language and we won't be able to cover all of it in a few "
"days. Some non-goals of this course are:"
msgstr ""
"Rust 是一门庞大的语言,我们无法在几天内涵盖所有内容。本课程的一些非目标包括:"
#: src/index.md:42
msgid ""
"Learning how to develop macros: please see [Chapter 19.5 in the Rust Book]"
"(https://doc.rust-lang.org/book/ch19-06-macros.html) and [Rust by Example]"
"(https://doc.rust-lang.org/rust-by-example/macros.html) instead."
msgstr ""
"了解如何开发宏,请参阅 [Rust Book 中的第 19.5 章](https://doc.rust-lang.org/"
"book/ch19-06-macros.html) 和 [Rust by Examples](https://doc.rust-lang.org/"
"rust-by-example/macros.html)。"
#: src/index.md:46
msgid "Assumptions"
msgstr "前提假设"
#: src/index.md:48
msgid ""
"The course assumes that you already know how to program. Rust is a "
"statically-typed language and we will sometimes make comparisons with C and "
"C++ to better explain or contrast the Rust approach."
msgstr ""
"本课程假设你已经具备编程知识。Rust 是一种静态类型语言,我们有时会与 C 和 C++ "
"进行比较,以更好地解释或对比 Rust 的方法。"
#: src/index.md:52
msgid ""
"If you know how to program in a dynamically-typed language such as Python or "
"JavaScript, then you will be able to follow along just fine too."
msgstr ""
"如果你已经了解如 Python 或 JavaScript 等动态类型语言的编程,那么你也能够很好"
"地跟上本课程。"
#: src/index.md:57
msgid ""
"This is an example of a _speaker note_. We will use these to add additional "
"information to the slides. This could be key points which the instructor "
"should cover as well as answers to typical questions which come up in class."
msgstr ""
"这是演讲者备注的示例。我们将使用这些备注来为幻灯片添加额外的信息。这可能包括"
"讲师应该涵盖的关键点,以及课堂上常见问题的答案。"
#: src/running-the-course.md:3 src/running-the-course/course-structure.md:3
msgid "This page is for the course instructor."
msgstr "本页面适用于课程教师。"
#: src/running-the-course.md:5
msgid ""
"Here is a bit of background information about how we've been running the "
"course internally at Google."
msgstr "以下是有关 Google 内部授课方式的一些背景信息。"
#: src/running-the-course.md:8
msgid ""
"We typically run classes from 10:00 am to 4:00 pm, with a 1 hour lunch break "
"in the middle. This leaves 2.5 hours for the morning class and 2.5 hours for "
"the afternoon class. Note that this is just a recommendation: you can also "
"spend 3 hour on the morning session to give people more time for exercises. "
"The downside of longer session is that people can become very tired after 6 "
"full hours of class in the afternoon."
msgstr ""
"上课时间通常是从上午 10:00 到下午 4:00,中间有 1 小时的午餐休息时间。这样,上"
"午和下午各留了 2.5 小时的上课时间。请注意,这仅是建议:您也可以上午上课 3 小"
"时,让学员有更多的时间进行练习。上课时间较长的缺点是,学员上了整整 6 小时的"
"课,到了下午可能会非常疲倦。"
#: src/running-the-course.md:16
msgid "Before you run the course, you will want to:"
msgstr "在授课之前,你需要完成以下事项:"
#: src/running-the-course.md:18
msgid ""
"Make yourself familiar with the course material. We've included speaker "
"notes to help highlight the key points (please help us by contributing more "
"speaker notes!). When presenting, you should make sure to open the speaker "
"notes in a popup (click the link with a little arrow next to \"Speaker "
"Notes\"). This way you have a clean screen to present to the class."
msgstr ""
"熟悉课程资料。我们添加了演讲者备注,借此强调要点(请帮个忙,多多贡献演讲者备"
"注!)。演示幻灯片时,你应确保在弹出式窗口中打开演讲者备注(点击对应的链接,"
"在“演讲者备注”旁边有一个小箭头)。这样,你就可以确保屏幕整洁有序,更好地向全"
"班学员展示课程内容。"
#: src/running-the-course.md:24
msgid ""
"Decide on the dates. Since the course takes at least three full days, we "
"recommend that you schedule the days over two weeks. Course participants "
"have said that they find it helpful to have a gap in the course since it "
"helps them process all the information we give them."
msgstr ""
"确定培训日期。由于本课程至少需要三天的时间,因此我们建议你安排两周以上的时"
"间。课程学员曾表示,在每堂课之间留一段间隔会很有帮助,因为这有利于他们吸收我"
"们所提供的所有信息。"
#: src/running-the-course.md:29
msgid ""
"Find a room large enough for your in-person participants. We recommend a "
"class size of 15-25 people. That's small enough that people are comfortable "
"asking questions --- it's also small enough that one instructor will have "
"time to answer the questions. Make sure the room has _desks_ for yourself "
"and for the students: you will all need to be able to sit and work with your "
"laptops. In particular, you will be doing a lot of live-coding as an "
"instructor, so a lectern won't be very helpful for you."
msgstr ""
"找一间足以容纳全体线下学员的大教室。我们建议你将课程人数控制在 15-25 人之间。"
"这样,人数足够少,不仅便于学员提问问题,配备的一位教师也有时间答疑解惑。确保"
"教室备有供你和学生使用的“课桌”:你们都需要能够坐下来并操作各自的笔记本电脑。"
"特别是身为教师,你现场要进行大量编码,所以讲台对你来说用处不大。"
#: src/running-the-course.md:37
msgid ""
"On the day of your course, show up to the room a little early to set things "
"up. We recommend presenting directly using `mdbook serve` running on your "
"laptop (see the [installation instructions](https://github.com/google/"
"comprehensive-rust#building)). This ensures optimal performance with no lag "
"as you change pages. Using your laptop will also allow you to fix typos as "
"you or the course participants spot them."
msgstr ""
"在开课当天,请提前一点到教室,设置好教学设备。我们建议你直接在笔记本电脑上运"
"行 `mdbook serve` 来演示课程内容(请参阅[安装说明](https://github.com/google/"
"comprehensive-rust#building))。这样可以确保你在切换页面时没有延迟,演示效果"
"更好。当你或课程学员发现拼写错误时,你也可以使用笔记本电脑及时更正。"
#: src/running-the-course.md:43
msgid ""
"Let people solve the exercises by themselves or in small groups. We "
"typically spend 30-45 minutes on exercises in the morning and in the "
"afternoon (including time to review the solutions). Make sure to ask people "
"if they're stuck or if there is anything you can help with. When you see "
"that several people have the same problem, call it out to the class and "
"offer a solution, e.g., by showing people where to find the relevant "
"information in the standard library."
msgstr ""
"让学员采取小组形式或独立解题。通常,我们会在上午和下午各安排 30-45 分钟的练习"
"时间(包括查看解决方案的时间)。请务必询问学员是否遇到困难,或是否需要任何帮"
"助。如果你看到多位学员遇到同样的问题,请在班级集体进行讲解,并提供相应的解决"
"方案,例如告诉大家在标准库的什么位置可以找到相关信息。"
#: src/running-the-course.md:51
msgid ""
"That is all, good luck running the course! We hope it will be as much fun "
"for you as it has been for us!"
msgstr "今天的分享就是这些,祝你授课顺利!希望你和我们一样,乐在其中!"
#: src/running-the-course.md:54
msgid ""
"Please [provide feedback](https://github.com/google/comprehensive-rust/"
"discussions/86) afterwards so that we can keep improving the course. We "
"would love to hear what worked well for you and what can be made better. "
"Your students are also very welcome to [send us feedback](https://github.com/"
"google/comprehensive-rust/discussions/100)!"
msgstr ""
"欢迎你课后[提供反馈](https://github.com/google/comprehensive-rust/"
"discussions/86),帮助我们不断改进课程。我们非常期待了解哪些方面做得不错,哪些"
"方面还需要改进。同时非常欢迎学生们[向我们发送反馈](https://github.com/google/"
"comprehensive-rust/discussions/100)!"
#: src/running-the-course/course-structure.md:5
msgid "Rust Fundamentals"
msgstr "Rust 基础知识"
#: src/running-the-course/course-structure.md:7
msgid ""
"The first three days make up [Rust Fundaments](../welcome-day-1.md). The "
"days are fast paced and we cover a lot of ground:"
msgstr ""
"我们会在头三天介绍 [Rust 基础知识](../welcome-day-1.md)。这几天的步调会稍快,"
"因为我们要探讨许多层面:"
#: src/running-the-course/course-structure.md:10
msgid "Day 1: Basic Rust, syntax, control flow, creating and consuming values."
msgstr "第 1 天:Rust 基础知识、语法、控制流、创建及使用值。"
#: src/running-the-course/course-structure.md:11
msgid ""
"Day 2: Memory management, ownership, compound data types, and the standard "
"library."
msgstr "第 2 天:内存管理、所有权、复合数据类类型及标准库。"
#: src/running-the-course/course-structure.md:12
msgid "Day 3: Generics, traits, error handling, testing, and unsafe Rust."
msgstr "第 3 天:泛型、trait、错误处理、测试和不安全 Rust。"
#: src/running-the-course/course-structure.md:14
msgid "Deep Dives"
msgstr "深入探究"
#: src/running-the-course/course-structure.md:16
msgid ""
"In addition to the 3-day class on Rust Fundamentals, we cover some more "
"specialized topics:"
msgstr "除了为期 3 天的“Rust 基础知识”课程外,我们还推出了一些专题课程:"
#: src/running-the-course/course-structure.md:19
msgid "Rust in Android"
msgstr "Android 中的 Rust"
#: src/running-the-course/course-structure.md:21
msgid ""
"The [Rust in Android](../android.md) deep dive is a half-day course on using "
"Rust for Android platform development. This includes interoperability with "
"C, C++, and Java."
msgstr ""
"[深入探究 Android](../android.md)课程为期半天,旨在介绍如何使用 Rust 进行 "
"Android 平台开发。其中包括与 C、C++ 和 Java 的互操作性。"
#: src/running-the-course/course-structure.md:25
msgid ""
"You will need an [AOSP checkout](https://source.android.com/docs/setup/"
"download/downloading). Make a checkout of the [course repository](https://"
"github.com/google/comprehensive-rust) on the same machine and move the `src/"
"android/` directory into the root of your AOSP checkout. This will ensure "
"that the Android build system sees the `Android.bp` files in `src/android/`."
msgstr ""
"你将需要[签出 AOSP](https://source.android.com/docs/setup/download/"
"downloading)。在同一机器上签出[课程库](https://github.com/google/"
"comprehensive-rust), 然后将 `src/android/` 目录移至所签出的 AOSP 的根目录。"
"这将确保 Android 构建系统能检测到 `src/android/` 中的 `Android.bp` 文件。"
#: src/running-the-course/course-structure.md:30
msgid ""
"Ensure that `adb sync` works with your emulator or real device and pre-build "
"all Android examples using `src/android/build_all.sh`. Read the script to "
"see the commands it runs and make sure they work when you run them by hand."
msgstr ""
"确保 `adb sync` 适用于你的模拟器或实际设备, 并使用 `src/android/build_all."
"sh` 预构建所有 Android 示例。请阅读脚本, 查看它所运行的命令,并确保这些命令"
"能在你手动运行时正确执行。"
#: src/running-the-course/course-structure.md:37
msgid "Bare-Metal Rust"
msgstr "裸金属 Rust"
#: src/running-the-course/course-structure.md:39
msgid ""
"The [Bare-Metal Rust](../bare-metal.md) deep dive is a full day class on "
"using Rust for bare-metal (embedded) development. Both microcontrollers and "
"application processors are covered."
msgstr ""
"[深入探究裸金属 Rust](../bare-metal.md)课程为期一天,旨在介绍如何使用 Rust 进"
"行裸金属(嵌入式)开发。其中涵盖了微控制器和应用处理器。"
#: src/running-the-course/course-structure.md:43
msgid ""
"For the microcontroller part, you will need to buy the [BBC micro:bit]"
"(https://microbit.org/) v2 development board ahead of time. Everybody will "
"need to install a number of packages as described on the [welcome page](../"
"bare-metal.md)."
msgstr ""
"对于微控制器部分,你需要提前购买 [BBC micro:bit](https://microbit.org/) 第 2 "
"版开发板。每个人都需要安装多个软件包, 具体如[欢迎页面](../bare-metal.md)中所"
"述。"
#: src/running-the-course/course-structure.md:48
msgid "Concurrency in Rust"
msgstr "Rust 中的并发"
#: src/running-the-course/course-structure.md:50
msgid ""
"The [Concurrency in Rust](../concurrency.md) deep dive is a full day class "
"on classical as well as `async`/`await` concurrency."
msgstr ""
"[深入探究并发](../concurrency.md)课程为期一天,旨在介绍传统并发和 `async`/"
"`await` 并发。"
#: src/running-the-course/course-structure.md:53
msgid ""
"You will need a fresh crate set up and the dependencies downloaded and ready "
"to go. You can then copy/paste the examples into `src/main.rs` to experiment "
"with them:"
msgstr ""
"你需要设置一个新 crate,下载所需的依赖项, 做好课前准备。然后,你可以将示例复"
"制/粘贴到 `src/main.rs` 中, 以便对以下代码进行实验:"
#: src/running-the-course/course-structure.md:64
msgid "Format"
msgstr "课程形式"
#: src/running-the-course/course-structure.md:66
msgid ""
"The course is meant to be very interactive and we recommend letting the "
"questions drive the exploration of Rust!"
msgstr "本课程的互动性非常强, 建议你以问题驱动探索 Rust!"
#: src/running-the-course/keyboard-shortcuts.md:3
msgid "There are several useful keyboard shortcuts in mdBook:"
msgstr "mdBook 中有一些实用键盘快捷键:"
#: src/running-the-course/keyboard-shortcuts.md:5
msgid "Arrow-Left"
msgstr "向左箭头"
#: src/running-the-course/keyboard-shortcuts.md:5
msgid ": Navigate to the previous page."
msgstr ":转到上一页。"
#: src/running-the-course/keyboard-shortcuts.md:6
msgid "Arrow-Right"
msgstr "向右箭头"
#: src/running-the-course/keyboard-shortcuts.md:6
msgid ": Navigate to the next page."
msgstr ":转到下一页。"
#: src/running-the-course/keyboard-shortcuts.md:7 src/cargo/code-samples.md:19
msgid "Ctrl + Enter"
msgstr "Ctrl + Enter"
#: src/running-the-course/keyboard-shortcuts.md:7
msgid ": Execute the code sample that has focus."
msgstr ":执行具有焦点的代码示例。"
#: src/running-the-course/keyboard-shortcuts.md:8
msgid "s"
msgstr "s"
#: src/running-the-course/keyboard-shortcuts.md:8
msgid ": Activate the search bar."
msgstr ":激活搜索栏。"
#: src/running-the-course/translations.md:3
msgid ""
"The course has been translated into other languages by a set of wonderful "
"volunteers:"
msgstr "一批优秀的志愿者已将本课程翻译成其他语言:"
#: src/running-the-course/translations.md:6
msgid ""
"[Brazilian Portuguese](https://google.github.io/comprehensive-rust/pt-BR/) "
"by [@rastringer](https://github.com/rastringer), [@hugojacob](https://github."
"com/hugojacob), [@joaovicmendes](https://github.com/joaovicmendes), and "
"[@henrif75](https://github.com/henrif75)."
msgstr ""
"[巴西葡萄牙语版本](https://google.github.io/comprehensive-rust/pt-BR/) 译者:"
"[@rastringer](https://github.com/rastringer)、[@hugojacob](https://github."
"com/hugojacob)、[@joaovicmendes](https://github.com/joaovicmendes) 和 "
"[@henrif75](https://github.com/henrif75)。"
#: src/running-the-course/translations.md:7
msgid ""
"[Korean](https://google.github.io/comprehensive-rust/ko/) by [@keispace]"
"(https://github.com/keispace), [@jiyongp](https://github.com/jiyongp), and "
"[@jooyunghan](https://github.com/jooyunghan)."
msgstr ""
"[韩语版本](https://google.github.io/comprehensive-rust/ko/) 译者:[@keispace]"
"(https://github.com/keispace)、[@jiyongp](https://github.com/jiyongp) 和 "
"[@jooyunghan](https://github.com/jooyunghan)。"
#: src/running-the-course/translations.md:8
msgid ""
"[Spanish](https://google.github.io/comprehensive-rust/es/) by [@deavid]"
"(https://github.com/deavid)."
msgstr ""
"[西班牙语版本](https://google.github.io/comprehensive-rust/es/) 译者:"
"[@deavid](https://github.com/deavid)。"
#: src/running-the-course/translations.md:10
msgid ""
"Use the language picker in the top-right corner to switch between languages."
msgstr "使用右上角的语言选择器切换语言。"
#: src/running-the-course/translations.md:12
msgid "Incomplete Translations"
msgstr "未完成的翻译"
#: src/running-the-course/translations.md:14
msgid ""
"There is a large number of in-progress translations. We link to the most "
"recently updated translations:"
msgstr "多数语言版本仍在翻译中。我们会提供最近更新的翻译的链接:"
#: src/running-the-course/translations.md:17
msgid ""
"[Bengali](https://google.github.io/comprehensive-rust/bn/) by [@raselmandol]"
"(https://github.com/raselmandol)."
msgstr ""
"[孟加拉语版本](https://google.github.io/comprehensive-rust/bn/) 译者:"
"[@raselmandol](https://github.com/raselmandol)。"
#: src/running-the-course/translations.md:18
msgid ""
"[Chinese (Traditional)](https://google.github.io/comprehensive-rust/zh-TW/) "
"by [@hueich](https://github.com/hueich), [@victorhsieh](https://github.com/"
"victorhsieh), [@mingyc](https://github.com/mingyc), and [@johnathan79717]"
"(https://github.com/johnathan79717)."
msgstr ""
"[繁体中文版本](https://google.github.io/comprehensive-rust/zh-TW/) 译者:"
"[@hueich](https://github.com/hueich)、[@victorhsieh](https://github.com/"
"victorhsieh)、[@mingyc](https://github.com/mingyc) 和 [@johnathan79717]"
"(https://github.com/johnathan79717)。"
#: src/running-the-course/translations.md:19
msgid ""
"[Chinese (Simplified)](https://google.github.io/comprehensive-rust/zh-CN/) "
"by [@suetfei](https://github.com/suetfei), [@wnghl](https://github.com/"
"wnghl), [@anlunx](https://github.com/anlunx), [@kongy](https://github.com/"
"kongy), [@noahdragon](https://github.com/noahdragon), and [@superwhd]"
"(https://github.com/superwhd)."
msgstr ""
"[简体中文版本](https://google.github.io/comprehensive-rust/zh-CN/) 译者:"
"[@suetfei](https://github.com/suetfei)、[@wnghl](https://github.com/wnghl), "
"[@anlunx](https://github.com/anlunx)、[@kongy](https://github.com/kongy), "
"[@noahdragon](https://github.com/noahdragon) 和 [@superwhd](https://github."
"com/superwhd)。"
#: src/running-the-course/translations.md:20
msgid ""
"[French](https://google.github.io/comprehensive-rust/fr/) by [@KookaS]"
"(https://github.com/KookaS) and [@vcaen](https://github.com/vcaen)."
msgstr ""
"[法语版本](https://google.github.io/comprehensive-rust/fr/) 译者:[@KookaS]"
"(https://github.com/KookaS) 和 [@vcaen](https://github.com/vcaen)。"
#: src/running-the-course/translations.md:21
msgid ""
"[German](https://google.github.io/comprehensive-rust/de/) by [@Throvn]"
"(https://github.com/Throvn) and [@ronaldfw](https://github.com/ronaldfw)."
msgstr ""
"[德语版本](https://google.github.io/comprehensive-rust/de/) 译者:[@Throvn]"
"(https://github.com/Throvn) 和 [@ronaldfw](https://github.com/ronaldfw)。"
#: src/running-the-course/translations.md:22
msgid ""
"[Japanese](https://google.github.io/comprehensive-rust/ja/) by [@CoinEZ-JPN]"
"(https://github.com/CoinEZ) and [@momotaro1105](https://github.com/"
"momotaro1105)."
msgstr ""
"[日语版本](https://google.github.io/comprehensive-rust/ja/) 译者:[@CoinEZ-"
"JPN](https://github.com/CoinEZ) 和 [@momotaro1105](https://github.com/"
"momotaro1105)。"
#: src/running-the-course/translations.md:24
msgid ""
"If you want to help with this effort, please see [our instructions](https://"
"github.com/google/comprehensive-rust/blob/main/TRANSLATIONS.md) for how to "
"get going. Translations are coordinated on the [issue tracker](https://"
"github.com/google/comprehensive-rust/issues/282)."
msgstr ""
"如果你想帮助我们,请参阅[我们的说明](https://github.com/google/comprehensive-"
"rust/blob/main/TRANSLATIONS.md),了解如何开始翻译。翻译工作将通过[问题跟踪器]"
"(https://github.com/google/comprehensive-rust/issues/282)跟踪。"
#: src/cargo.md:3
msgid ""
"When you start reading about Rust, you will soon meet [Cargo](https://doc."
"rust-lang.org/cargo/), the standard tool used in the Rust ecosystem to build "
"and run Rust applications. Here we want to give a brief overview of what "
"Cargo is and how it fits into the wider ecosystem and how it fits into this "
"training."
msgstr ""
"开始了解 Rust 后,你很快就会遇到 [Cargo](https://doc.rust-lang.org/cargo/),"
"这是 Rust 生态系统中用于构建和运行 Rust 应用的标准工具。在这里,我们想简要介"
"绍一下什么是 Cargo、它如何融入更广泛的生态系统, 以及我们如何在本培训中合理利"
"用 Cargo。"
#: src/cargo.md:8
msgid "Installation"
msgstr "安装"
#: src/cargo.md:10
msgid "**Please follow the instructions on .**"
msgstr "**请按照 上的说明操作。**"
#: src/cargo.md:12
msgid ""
"This will give you the Cargo build tool (`cargo`) and the Rust compiler "
"(`rustc`). You will also get `rustup`, a command line utility that you can "
"use to install to different compiler versions."
msgstr ""
"这将为你提供 Cargo 构建工具 (`cargo`)和 Rust 编译器 (`rustc`)。你还将获得 "
"`rustup`,这是一个命令行实用程序,你可以用它来安装不同的编译器版本。"
#: src/cargo.md:14
msgid ""
"After installing Rust, you should configure your editor or IDE to work with "
"Rust. Most editors do this by talking to [rust-analyzer](https://rust-"
"analyzer.github.io/), which provides auto-completion and jump-to-definition "
"functionality for [VS Code](https://code.visualstudio.com/), [Emacs](https://"
"rust-analyzer.github.io/manual.html#emacs), [Vim/Neovim](https://rust-"
"analyzer.github.io/manual.html#vimneovim), and many others. There is also a "
"different IDE available called [RustRover](https://www.jetbrains.com/rust/)."
msgstr ""
"安装Rust之后,你应当配置你的编辑器或 IDE 以开始使用 Rust。大多数编辑器使用"
"[rust-analyzer](https://rust-analyzer.github.io/)以达成此目的。它为[VS Code]"
"(https://code.visualstudio.com/)、[Emacs](https://rust-analyzer.github.io/"
"manual.html#emacs)、[Vim/Neovim](https://rust-analyzer.github.io/manual."
"html#vimneovim)及其他许多编辑器提供了自动补全及定义跳转的功能。同样也可以用一"
"个叫[RustRover](https://www.jetbrains.com/rust/)的IDE。"
#: src/cargo.md:18
msgid ""
"On Debian/Ubuntu, you can also install Cargo, the Rust source and the [Rust "
"formatter](https://github.com/rust-lang/rustfmt) via `apt`. However, this "
"gets you an outdated rust version and may lead to unexpected behavior. The "
"command would be:"
msgstr ""
"在 Debian/Ubuntu 上,你也可以通过 `apt` 安装 Cargo、Rust 源代码和 [Rust 格式"
"化工具](https://github.com/rust-lang/rustfmt)。但是,这样会得到一个过时的 "
"Rust 版本,这可能会导致意外的行为。命令如下:"
#: src/cargo/rust-ecosystem.md:1
msgid "The Rust Ecosystem"
msgstr "Rust 生态系统"
#: src/cargo/rust-ecosystem.md:3
msgid ""
"The Rust ecosystem consists of a number of tools, of which the main ones are:"
msgstr "Rust 生态系统由许多工具组成,其中的主要工具包括:"
#: src/cargo/rust-ecosystem.md:5
msgid ""
"`rustc`: the Rust compiler which turns `.rs` files into binaries and other "
"intermediate formats."
msgstr "`rustc`:Rust 编译器,可将 `.rs` 文件转换为二进制文件和其他中间格式。"
#: src/cargo/rust-ecosystem.md:8
msgid ""
"`cargo`: the Rust dependency manager and build tool. Cargo knows how to "
"download dependencies, usually hosted on , and it will "
"pass them to `rustc` when building your project. Cargo also comes with a "
"built-in test runner which is used to execute unit tests."
msgstr ""
"`cargo`:Rust 依赖项管理器和构建工具。Cargo 知道如何下载托管在 上的依赖项,并在构建项目时将它们传递给 `rustc`。Cargo 还附带一个内"
"置的测试运行程序,用于执行单元测试。"
#: src/cargo/rust-ecosystem.md:13
msgid ""
"`rustup`: the Rust toolchain installer and updater. This tool is used to "
"install and update `rustc` and `cargo` when new versions of Rust is "
"released. In addition, `rustup` can also download documentation for the "
"standard library. You can have multiple versions of Rust installed at once "
"and `rustup` will let you switch between them as needed."
msgstr ""
"`rustup`:Rust 工具链安装程序和更新程序。发布新版本 Rust 时,此工具用于安装并"
"更新 `rustc` 和 `cargo`。 此外,`rustup` 还可以下载标准库的文档。你可以同时安"
"装多个版本的 Rust,并且 `rustup` 可让你根据需要在这些版本之间切换。"
#: src/cargo/rust-ecosystem.md:21 src/hello-world.md:25
#: src/hello-world/small-example.md:27 src/why-rust/runtime.md:10
#: src/why-rust/modern.md:21 src/basic-syntax/compound-types.md:32
#: src/basic-syntax/references.md:24
#: src/pattern-matching/destructuring-enums.md:35
#: src/ownership/double-free-modern-cpp.md:55
#: src/error-handling/try-operator.md:48
#: src/error-handling/converting-error-types-example.md:50
#: src/concurrency/threads.md:30 src/async/async-await.md:25
msgid "Key points:"
msgstr "关键点:"
#: src/cargo/rust-ecosystem.md:23
msgid ""
"Rust has a rapid release schedule with a new release coming out every six "
"weeks. New releases maintain backwards compatibility with old releases --- "
"plus they enable new functionality."
msgstr ""
"Rust 有一个快速发布时间表,每六周就会发布一次 新版本。新版本保持与旧版本的向"
"后兼容性,还添加了新功能。"
#: src/cargo/rust-ecosystem.md:27
msgid ""
"There are three release channels: \"stable\", \"beta\", and \"nightly\"."
msgstr "共有三个发布阶段:“稳定版”、“Beta 版”和“夜间版”。"
#: src/cargo/rust-ecosystem.md:29
msgid ""
"New features are being tested on \"nightly\", \"beta\" is what becomes "
"\"stable\" every six weeks."
msgstr "我们会在“夜间版”上测试新功能,每六周将“Beta 版”升级为“稳定版”。"
#: src/cargo/rust-ecosystem.md:32
msgid ""
"Dependencies can also be resolved from alternative [registries](https://doc."
"rust-lang.org/cargo/reference/registries.html), git, folders, and more."
msgstr ""
"您也可以通过备用的[注册数据库](https://doc.rust-lang.org/cargo/reference/"
"registries.html)、git及文件夹等资源来解析依赖项。"
#: src/cargo/rust-ecosystem.md:34
msgid ""
"Rust also has [editions](https://doc.rust-lang.org/edition-guide/): the "
"current edition is Rust 2021. Previous editions were Rust 2015 and Rust 2018."
msgstr ""
"Rust 也有三个\\[版本\\]:当前版本是 Rust 2021。之前的版本是 Rust 2015 和 "
"Rust 2018。"
#: src/cargo/rust-ecosystem.md:37
msgid ""
"The editions are allowed to make backwards incompatible changes to the "
"language."
msgstr "这些版本支持对语言进行向后不兼容的更改。"
#: src/cargo/rust-ecosystem.md:40
msgid ""
"To prevent breaking code, editions are opt-in: you select the edition for "
"your crate via the `Cargo.toml` file."
msgstr ""
"为防止破坏代码,你可以自行选择版本: 通过 `Cargo.toml` 文件为 crate 选择合适"
"的版本。"
#: src/cargo/rust-ecosystem.md:43
msgid ""
"To avoid splitting the ecosystem, Rust compilers can mix code written for "
"different editions."
msgstr "为免分割生态系统,Rust 编译器可以混合使用为不同版本编写的代码。"
#: src/cargo/rust-ecosystem.md:46
msgid ""
"Mention that it is quite rare to ever use the compiler directly not through "
"`cargo` (most users never do)."
msgstr ""
"提及不通过 `cargo` 而直接使用编译器的情况相当少见(大多数用户从不这样做)。"
#: src/cargo/rust-ecosystem.md:48
msgid ""
"It might be worth alluding that Cargo itself is an extremely powerful and "
"comprehensive tool. It is capable of many advanced features including but "
"not limited to: "
msgstr ""
"值得注意的是,Cargo 本身就是一个功能强大且全面的工具。它能够实现许多高级功"
"能,包括但不限于:"
#: src/cargo/rust-ecosystem.md:49
msgid "Project/package structure"
msgstr "项目/软件包结构"
#: src/cargo/rust-ecosystem.md:50
msgid "[workspaces](https://doc.rust-lang.org/cargo/reference/workspaces.html)"
msgstr "\\[工作区\\]"
#: src/cargo/rust-ecosystem.md:51
msgid "Dev Dependencies and Runtime Dependency management/caching"
msgstr "开发依赖项和运行时依赖项管理/缓存"
#: src/cargo/rust-ecosystem.md:52
msgid ""
"[build scripting](https://doc.rust-lang.org/cargo/reference/build-scripts."
"html)"
msgstr "\\[构建脚本\\]"
#: src/cargo/rust-ecosystem.md:53
msgid ""
"[global installation](https://doc.rust-lang.org/cargo/commands/cargo-install."
"html)"
msgstr "\\[全局安装\\] \\]"
#: src/cargo/rust-ecosystem.md:54
msgid ""
"It is also extensible with sub command plugins as well (such as [cargo "
"clippy](https://github.com/rust-lang/rust-clippy))."
msgstr ""
"它还可以使用子命令插件(例如 [cargo clippy](https://github.com/rust-lang/"
"rust-clippy))进行扩展。"
#: src/cargo/rust-ecosystem.md:55
msgid ""
"Read more from the [official Cargo Book](https://doc.rust-lang.org/cargo/)"
msgstr "如需了解详情,请参阅\\[ Cargo 官方图书\\]"
#: src/cargo/code-samples.md:1
msgid "Code Samples in This Training"
msgstr "本培训中的代码示例"
#: src/cargo/code-samples.md:3
msgid ""
"For this training, we will mostly explore the Rust language through examples "
"which can be executed through your browser. This makes the setup much easier "
"and ensures a consistent experience for everyone."
msgstr ""
"在本培训中,我们将主要通过示例探索 Rust 语言,这些示例可通过浏览器执行。这能"
"大大简化设置过程, 并确保所有人都能获得一致的体验。"
#: src/cargo/code-samples.md:7
msgid ""
"Installing Cargo is still encouraged: it will make it easier for you to do "
"the exercises. On the last day, we will do a larger exercise which shows you "
"how to work with dependencies and for that you need Cargo."
msgstr ""
"我们仍然建议你安装 Cargo:它有助于你更轻松地完成练习。在最后一天,我们要做一"
"个更大的练习, 向你展示如何使用依赖项,因此你需要安装 Cargo。"
#: src/cargo/code-samples.md:11
msgid "The code blocks in this course are fully interactive:"
msgstr "本课程中的代码块是完全交互式的:"
#: src/cargo/code-samples.md:13
msgid ""
"```rust,editable\n"
"fn main() {\n"
" println!(\"Edit me!\");\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"fn main() {\n"
" println!(\"Edit me!\");\n"
"}\n"
"```"
#: src/cargo/code-samples.md:19
msgid "You can use "
msgstr "当文本框为焦点时,你可以使用"
#: src/cargo/code-samples.md:19
#, fuzzy
msgid "to execute the code when focus is in the text box."
msgstr "来执行代码。"
#: src/cargo/code-samples.md:24
msgid ""
"Most code samples are editable like shown above. A few code samples are not "
"editable for various reasons:"
msgstr ""
"大多数代码示例都可修改(如上图所示)。少数代码示例可能会因各种原因而不可修"
"改:"
#: src/cargo/code-samples.md:27
msgid ""
"The embedded playgrounds cannot execute unit tests. Copy-paste the code and "
"open it in the real Playground to demonstrate unit tests."
msgstr ""
"嵌入式 Playground 无法执行单元测试。将代码复制并粘贴到实际 Playground 中,以"
"演示单元测试。"
#: src/cargo/code-samples.md:30
msgid ""
"The embedded playgrounds lose their state the moment you navigate away from "
"the page! This is the reason that the students should solve the exercises "
"using a local Rust installation or via the Playground."
msgstr ""
"嵌入式 Playground 会在你离开页面后立即丢失其状态!正因如此,学员应使用本地安"
"装的 Rust 或通过 Playground 解题。"
#: src/cargo/running-locally.md:1
msgid "Running Code Locally with Cargo"
msgstr "使用 Cargo 在本地运行代码"
#: src/cargo/running-locally.md:3
msgid ""
"If you want to experiment with the code on your own system, then you will "
"need to first install Rust. Do this by following the [instructions in the "
"Rust Book](https://doc.rust-lang.org/book/ch01-01-installation.html). This "
"should give you a working `rustc` and `cargo`. At the time of writing, the "
"latest stable Rust release has these version numbers:"
msgstr ""
"如果你想在自己的系统上对代码进行实验, 则需要先安装 Rust。为此,请按照 [Rust "
"图书中的说明](https://doc.rust-lang.org/book/ch01-01-installation.html)操作。"
"这应会为你提供一个有效的 `rustc` 和 `cargo`。在撰写本文时,最新的 Rust 稳定版"
"具有以下版本号:"
#: src/cargo/running-locally.md:15
msgid ""
"You can use any later version too since Rust maintains backwards "
"compatibility."
msgstr "您也可以使用任何更高版本,因为 Rust 保持向后兼容性。"
#: src/cargo/running-locally.md:17
msgid ""
"With this in place, follow these steps to build a Rust binary from one of "
"the examples in this training:"
msgstr ""
"了解这些信息后,请按照以下步骤从本培训中的 一个示例中构建 Rust 二进制文件:"
#: src/cargo/running-locally.md:20
msgid "Click the \"Copy to clipboard\" button on the example you want to copy."
msgstr "在你要复制的示例上点击“复制到剪贴板”按钮。"
#: src/cargo/running-locally.md:22
msgid ""
"Use `cargo new exercise` to create a new `exercise/` directory for your code:"
msgstr "使用 `cargo new exercise` 为你的代码新建一个 `exercise/` 目录:"
#: src/cargo/running-locally.md:29
msgid ""
"Navigate into `exercise/` and use `cargo run` to build and run your binary:"
msgstr "导航至 `exercise/` 并使用 `cargo run` 构建并运行你的二进制文件:"
#: src/cargo/running-locally.md:40
msgid ""
"Replace the boiler-plate code in `src/main.rs` with your own code. For "
"example, using the example on the previous page, make `src/main.rs` look like"
msgstr ""
"将 `src/main.rs` 中的样板代码替换为你自己的代码。例如, 使用上一页中的示例,"
"将 `src/main.rs` 改为:"
#: src/cargo/running-locally.md:43
msgid ""
"```rust\n"
"fn main() {\n"
" println!(\"Edit me!\");\n"
"}\n"
"```"
msgstr ""
"```rust\n"
"fn main() {\n"
" println!(\"Edit me!\");\n"
"}\n"
"```"
#: src/cargo/running-locally.md:49
msgid "Use `cargo run` to build and run your updated binary:"
msgstr "使用 `cargo run` 构建并运行你更新后的二进制文件:"
#: src/cargo/running-locally.md:59
msgid ""
"Use `cargo check` to quickly check your project for errors, use `cargo "
"build` to compile it without running it. You will find the output in `target/"
"debug/` for a normal debug build. Use `cargo build --release` to produce an "
"optimized release build in `target/release/`."
msgstr ""
"使用 `cargo check` 快速检查项目是否存在错误;使用 `cargo build` 只进行编译,"
"而不运行。你可以在 `target/debug/` 中找到常规调试 build 的输出。使用 `cargo "
"build --release` 在 `target/release/` 中生成经过优化的 发布 build。"
#: src/cargo/running-locally.md:64
msgid ""
"You can add dependencies for your project by editing `Cargo.toml`. When you "
"run `cargo` commands, it will automatically download and compile missing "
"dependencies for you."
msgstr ""
"你可以通过修改 `Cargo.toml` 为项目添加依赖项。当你 运行 `cargo` 命令时,系统"
"会自动为你下载和编译缺失 的依赖项。"
#: src/cargo/running-locally.md:72
msgid ""
"Try to encourage the class participants to install Cargo and use a local "
"editor. It will make their life easier since they will have a normal "
"development environment."
msgstr ""
"尽量鼓励全班学员安装 Cargo 并使用 本地编辑器。这能为他们营造常规 开发环境,让"
"工作变得更加轻松。"
#: src/welcome-day-1.md:1
msgid "Welcome to Day 1"
msgstr "欢迎来到第一天"
#: src/welcome-day-1.md:3
msgid ""
"This is the first day of Rust Fundamentals. We will cover a lot of ground "
"today:"
msgstr "今天是学习 Comprehensive Rust 的第一天。我们会涉及很多内容:"
#: src/welcome-day-1.md:6
msgid ""
"Basic Rust syntax: variables, scalar and compound types, enums, structs, "
"references, functions, and methods."
msgstr ""
"Rust 基本语法:变量、标量(scalar)和复合(compound)类型、枚举(Enum)、结构"
"体(struct)、引用、函数和方法。"
#: src/welcome-day-1.md:9
msgid ""
"Control flow constructs: `if`, `if let`, `while`, `while let`, `break`, and "
"`continue`."
msgstr ""
"控制流的构造:`if`、`if let`、`while`、`while let`、`break` 和 `continue`。"
#: src/welcome-day-1.md:12
msgid "Pattern matching: destructuring enums, structs, and arrays."
msgstr "模式匹配:解构枚举、结构体和数组(array)。"
#: src/welcome-day-1.md:16
msgid "Please remind the students that:"
msgstr "请提醒学生:"
#: src/welcome-day-1.md:18
msgid ""
"They should ask questions when they get them, don't save them to the end."
msgstr "他们可以随时提问,不需要留到最后。"
#: src/welcome-day-1.md:19
msgid ""
"The class is meant to be interactive and discussions are very much "
"encouraged!"
msgstr "这个课程本应该是互动的,我们鼓励大家积极讨论。"
#: src/welcome-day-1.md:20
#, fuzzy
msgid ""
"As an instructor, you should try to keep the discussions relevant, i.e., "
"keep the discussions related to how Rust does things vs some other "
"language. It can be hard to find the right balance, but err on the side of "
"allowing discussions since they engage people much more than one-way "
"communication."
msgstr ""
"作为讲师,你应该尽量保证讨论话题的相关性,例如,讨论围绕Rust是如何做某些事"
"情,而不是其他的语言如何如何。 这个平衡点不容易找到,但是尽量倾向于允许讨论,"
"因为讨论比起单方面的灌输更有利于让大家投入。"
#: src/welcome-day-1.md:24
msgid ""
"The questions will likely mean that we talk about things ahead of the slides."
msgstr "有些问题会导致我们提前谈到后面的内容。"
#: src/welcome-day-1.md:25
msgid ""
"This is perfectly okay! Repetition is an important part of learning. "
"Remember that the slides are just a support and you are free to skip them as "
"you like."
msgstr ""
"这完全没有问题!重复是学习的一个重要方法。请记住,这些幻灯片只是一种辅助,你"
"可以选择性地跳过。"
#: src/welcome-day-1.md:29
msgid ""
"The idea for the first day is to show _just enough_ of Rust to be able to "
"speak about the famous borrow checker. The way Rust handles memory is a "
"major feature and we should show students this right away."
msgstr ""
"第一天的主要目标是要谈到著名的 borrow checker,其他方面点到为止。Rust 处理内"
"存的方式是其主要特点,这点我们应该尽早展示给学生。"
#: src/welcome-day-1.md:33
msgid ""
"If you're teaching this in a classroom, this is a good place to go over the "
"schedule. We suggest splitting the day into two parts (following the slides):"
msgstr ""
"如果你是在教室里教授此课程,不妨在这里介绍一下时间安排。 这边建议是把每天分成"
"两部分(跟着幻灯片来):"
#: src/welcome-day-1.md:36
msgid "Morning: 9:00 to 12:00,"
msgstr "早上:9:00 到 12:00,"
#: src/welcome-day-1.md:37
msgid "Afternoon: 13:00 to 16:00."
msgstr "下午:13:00 到 16:00。"
#: src/welcome-day-1.md:39
msgid ""
"You can of course adjust this as necessary. Please make sure to include "
"breaks, we recommend a break every hour!"
msgstr ""
"当然你也可以看情况调整时间。但是请务必记得提供休息时间。我们建议每个小时休息"
"一次!"
#: src/welcome-day-1/what-is-rust.md:3
msgid ""
"Rust is a new programming language which had its [1.0 release in 2015]"
"(https://blog.rust-lang.org/2015/05/15/Rust-1.0.html):"
msgstr ""
"Rust 是一门新的编程语言,它的[1.0 版本于 2015 年发布](https://blog.rust-lang."
"org/2015/05/15/Rust-1.0.html):"
#: src/welcome-day-1/what-is-rust.md:5
msgid "Rust is a statically compiled language in a similar role as C++"
msgstr "Rust 是一门静态编译语言,其功能定位与 C++ 相似"
#: src/welcome-day-1/what-is-rust.md:6
msgid "`rustc` uses LLVM as its backend."
msgstr "`rustc` 使用 LLVM 作为它的后端。"
#: src/welcome-day-1/what-is-rust.md:7
msgid ""
"Rust supports many [platforms and architectures](https://doc.rust-lang.org/"
"nightly/rustc/platform-support.html):"
msgstr ""
"Rust 支持多种[平台和架构](https://doc.rust-lang.org/nightly/rustc/platform-"
"support.html):"
#: src/welcome-day-1/what-is-rust.md:9
msgid "x86, ARM, WebAssembly, ..."
msgstr "x86、ARM、WebAssembly......"
#: src/welcome-day-1/what-is-rust.md:10
msgid "Linux, Mac, Windows, ..."
msgstr "Linux、Mac、Windows......"
#: src/welcome-day-1/what-is-rust.md:11
msgid "Rust is used for a wide range of devices:"
msgstr "Rust 被广泛用于各种设备中:"
#: src/welcome-day-1/what-is-rust.md:12
msgid "firmware and boot loaders,"
msgstr "固件和引导程序,"
#: src/welcome-day-1/what-is-rust.md:13
msgid "smart displays,"
msgstr "智能显示器,"
#: src/welcome-day-1/what-is-rust.md:14
msgid "mobile phones,"
msgstr "手机,"
#: src/welcome-day-1/what-is-rust.md:15
msgid "desktops,"
msgstr "桌面,"
#: src/welcome-day-1/what-is-rust.md:16
msgid "servers."
msgstr "服务器。"
#: src/welcome-day-1/what-is-rust.md:21
msgid "Rust fits in the same area as C++:"
msgstr "Rust 和 C++ 适用于类似的场景:"
#: src/welcome-day-1/what-is-rust.md:23
msgid "High flexibility."
msgstr "极高的灵活性。"
#: src/welcome-day-1/what-is-rust.md:24
msgid "High level of control."
msgstr "高度的控制能力。"
#: src/welcome-day-1/what-is-rust.md:25
msgid ""
"Can be scaled down to very constrained devices such as microcontrollers."
msgstr "能够在资源匮乏的设备(如手机)上运行。"
#: src/welcome-day-1/what-is-rust.md:26
msgid "Has no runtime or garbage collection."
msgstr "没有运行时和垃圾收集。"
#: src/welcome-day-1/what-is-rust.md:27
msgid "Focuses on reliability and safety without sacrificing performance."
msgstr "关注程序可靠性和安全性,而不会牺牲任何性能。"
#: src/hello-world.md:3
msgid ""
"Let us jump into the simplest possible Rust program, a classic Hello World "
"program:"
msgstr "让我们进入最简单的 Rust 程序,一个经典的 Hello World 程序:"
#: src/hello-world.md:6
msgid ""
"```rust,editable\n"
"fn main() {\n"
" println!(\"Hello 🌍!\");\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"fn main() {\n"
" println!(\"Hello 🌍!\");\n"
"}\n"
"```"
#: src/hello-world.md:12
msgid "What you see:"
msgstr "你看到的:"
#: src/hello-world.md:14
msgid "Functions are introduced with `fn`."
msgstr "函数以 `fn` 开头。"
#: src/hello-world.md:15
msgid "Blocks are delimited by curly braces like in C and C++."
msgstr "像 C 和 C++ 一样,块由花括号分隔。"
#: src/hello-world.md:16
msgid "The `main` function is the entry point of the program."
msgstr "`main` 函数是程序的入口点。"
#: src/hello-world.md:17
msgid "Rust has hygienic macros, `println!` is an example of this."
msgstr "Rust 有卫生宏 (hygienic macros),`println!` 就是一个例子。"
#: src/hello-world.md:18
msgid "Rust strings are UTF-8 encoded and can contain any Unicode character."
msgstr "Rust 字符串是 UTF-8 编码的,可以包含任何 Unicode 字符。"
#: src/hello-world.md:22
#, fuzzy
msgid ""
"This slide tries to make the students comfortable with Rust code. They will "
"see a ton of it over the next three days so we start small with something "
"familiar."
msgstr ""
"这张幻灯片试图让学生们熟悉 Rust 代码。在接下来的四天里,他们会看到很多 Rust "
"代码, 所以我们从一些熟悉的东西开始。"
#: src/hello-world.md:27
#, fuzzy
msgid ""
"Rust is very much like other languages in the C/C++/Java tradition. It is "
"imperative and it doesn't try to reinvent things unless absolutely necessary."
msgstr ""
"Rust 非常像 C/C++/Java 等其他传统语言。它是指令式语言(而非函数式),而且除非"
"绝对必要,它不会尝试重新发明新的概念。"
#: src/hello-world.md:31
msgid "Rust is modern with full support for things like Unicode."
msgstr "Rust 是一门现代编程语言,它完全支持 Unicode 等特性。"
#: src/hello-world.md:33
msgid ""
"Rust uses macros for situations where you want to have a variable number of "
"arguments (no function [overloading](basic-syntax/functions-interlude.md))."
msgstr ""
"在需要处理可变数量的参数的情况下,Rust 使用宏(没有函数[重载](basic-syntax/"
"functions-interlude.md))。"
#: src/hello-world.md:36
msgid ""
"Macros being 'hygienic' means they don't accidentally capture identifiers "
"from the scope they are used in. Rust macros are actually only [partially "
"hygienic](https://veykril.github.io/tlborm/decl-macros/minutiae/hygiene."
"html)."
msgstr ""
"宏是“卫生的”,这意味着它们不会意外地捕获它们所在作用域中的标识符。实际上,"
"Rust 的宏只是[部分卫生](https://veykril.github.io/tlborm/decl-macros/"
"minutiae/hygiene.html)。"
#: src/hello-world.md:40
msgid ""
"Rust is multi-paradigm. For example, it has powerful [object-oriented "
"programming features](https://doc.rust-lang.org/book/ch17-00-oop.html), and, "
"while it is not a functional language, it includes a range of [functional "
"concepts](https://doc.rust-lang.org/book/ch13-00-functional-features.html)."
msgstr ""
"Rust 是多范式编程语言。例如,它具有强大的[面向对象的编程功能](https://doc."
"rust-lang.org/book/ch17-00-oop.html),虽然它不是函数式语言,但包括一系列的[函"
"数概念](https://doc.rust-lang.org/book/ch13-00-functional-features.html)。"
#: src/hello-world/small-example.md:3
msgid "Here is a small example program in Rust:"
msgstr "以下是一个简短的 Rust 示例程序:"
#: src/hello-world/small-example.md:5
msgid ""
"```rust,editable\n"
"fn main() { // Program entry point\n"
" let mut x: i32 = 6; // Mutable variable binding\n"
" print!(\"{x}\"); // Macro for printing, like printf\n"
" while x != 1 { // No parenthesis around expression\n"
" if x % 2 == 0 { // Math like in other languages\n"
" x = x / 2;\n"
" } else {\n"
" x = 3 * x + 1;\n"
" }\n"
" print!(\" -> {x}\");\n"
" }\n"
" println!();\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"fn main() { // 程序入口\n"
" let mut x: i32 = 6; // 可变变量绑定\n"
" print!(\"{x}\"); // 与 printf 类似的输出宏\n"
" while x != 1 { // 表达式周围没有括号\n"
" if x % 2 == 0 { // 与其他语言类似的数值计算\n"
" x = x / 2;\n"
" } else {\n"
" x = 3 * x + 1;\n"
" }\n"
" print!(\" -> {x}\");\n"
" }\n"
" println!();\n"
"}\n"
"```"
#: src/hello-world/small-example.md:23
msgid ""
"The code implements the Collatz conjecture: it is believed that the loop "
"will always end, but this is not yet proved. Edit the code and play with "
"different inputs."
msgstr ""
"这段代码实现了 Collatz 猜想:猜想认为该循环总是会结束,但该猜想还没有被证明。"
"可以编辑代码来尝试不同的输入。"
#: src/hello-world/small-example.md:29
msgid ""
"Explain that all variables are statically typed. Try removing `i32` to "
"trigger type inference. Try with `i8` instead and trigger a runtime integer "
"overflow."
msgstr ""
"说明所有变量的类型都是静态的。尝试删除 `i32` 来触发类型推断。尝试使用 `i8` 来"
"触发运行时整数溢出。"
#: src/hello-world/small-example.md:32
msgid "Change `let mut x` to `let x`, discuss the compiler error."
msgstr "将 `let mut x` 改为 `let x`,讨论出现的编译错误。"
#: src/hello-world/small-example.md:34
msgid ""
"Show how `print!` gives a compilation error if the arguments don't match the "
"format string."
msgstr "展示 `print!` 在参数与格式字符串不匹配时产生的编译错误。"
#: src/hello-world/small-example.md:37
msgid ""
"Show how you need to use `{}` as a placeholder if you want to print an "
"expression which is more complex than just a single variable."
msgstr "展示如何使用 `{}` 作为占位符,来输出比单个变量更复杂的表达式。"
#: src/hello-world/small-example.md:40
msgid ""
"Show the students the standard library, show them how to search for `std::"
"fmt` which has the rules of the formatting mini-language. It's important "
"that the students become familiar with searching in the standard library."
msgstr ""
"向学生展示标准库,展示如何搜索 `std::fmt`,其中包含用于格式化字符串的微型语言"
"规则。要点是让学生熟悉在标准库中搜索的过程。"
#: src/hello-world/small-example.md:44
msgid ""
"In a shell `rustup doc std::fmt` will open a browser on the local std::fmt "
"documentation"
msgstr ""
"在 shell 中,运行 `rustup doc std::fmt` 会在浏览器中打开本地 std::fmt 文档"
#: src/why-rust.md:3
msgid "Some unique selling points of Rust:"
msgstr "Rust 有一些独特的卖点:"
#: src/why-rust.md:5
msgid "Compile time memory safety."
msgstr "编译期内存安全。"
#: src/why-rust.md:6
msgid "Lack of undefined runtime behavior."
msgstr "没有运行时未定义行为。"
#: src/why-rust.md:7
msgid "Modern language features."
msgstr "现代的编程语言特性。"
#: src/why-rust.md:11
msgid ""
"Make sure to ask the class which languages they have experience with. "
"Depending on the answer you can highlight different features of Rust:"
msgstr "应该问问学生们都使用过哪些语言。根据答案侧重讲解 Rust 的不同特性:"
#: src/why-rust.md:14
msgid ""
"Experience with C or C++: Rust eliminates a whole class of _runtime errors_ "
"via the borrow checker. You get performance like in C and C++, but you don't "
"have the memory unsafety issues. In addition, you get a modern language with "
"constructs like pattern matching and built-in dependency management."
msgstr ""
"使用过 C 或 C++:Rust 利用借用检查消除了一类 _运行时错误_ 。你可以达到堪比 C "
"和 C++ 的性能,而没有内存不安全的问题。并且你还可以得到些现代的语言构造,比如"
"模式匹配和内置依赖管理。"
#: src/why-rust.md:19
msgid ""
"Experience with Java, Go, Python, JavaScript...: You get the same memory "
"safety as in those languages, plus a similar high-level language feeling. In "
"addition you get fast and predictable performance like C and C++ (no garbage "
"collector) as well as access to low-level hardware (should you need it)"
msgstr ""
"使用过 Java、Go、Python、JavaScript......:你可以得到和这些语言相同的内存安全"
"特性,并拥有类似的使用高级语言的感受。同时你可以得到类似 C 和 C++ 的高速且可"
"预测的执行性能(无垃圾回收机制),以及在需要时对底层硬件的访问。"
#: src/why-rust/an-example-in-c.md:4
msgid "Let's consider the following \"minimum wrong example\" program in C:"
msgstr "让我们查看以下 C 语言的“最小错误示例”程序:"
#: src/why-rust/an-example-in-c.md:6
msgid ""
"```c,editable\n"
"#include \n"
"#include \n"
"#include \n"
"\n"
"int main(int argc, char* argv[]) {\n"
"\tchar *buf, *filename;\n"
"\tFILE *fp;\n"
"\tsize_t bytes, len;\n"
"\tstruct stat st;\n"
"\n"
"\tswitch (argc) {\n"
"\t\tcase 1:\n"
"\t\t\tprintf(\"Too few arguments!\\n\");\n"
"\t\t\treturn 1;\n"
"\n"
"\t\tcase 2:\n"
"\t\t\tfilename = argv[argc];\n"
"\t\t\tstat(filename, &st);\n"
"\t\t\tlen = st.st_size;\n"
"\t\t\t\n"
"\t\t\tbuf = (char*)malloc(len);\n"
"\t\t\tif (!buf)\n"
"\t\t\t\tprintf(\"malloc failed!\\n\", len);\n"
"\t\t\t\treturn 1;\n"
"\n"
"\t\t\tfp = fopen(filename, \"rb\");\n"
"\t\t\tbytes = fread(buf, 1, len, fp);\n"
"\t\t\tif (bytes = st.st_size)\n"
"\t\t\t\tprintf(\"%s\", buf);\n"
"\t\t\telse\n"
"\t\t\t\tprintf(\"fread failed!\\n\");\n"
"\n"
"\t\tcase 3:\n"
"\t\t\tprintf(\"Too many arguments!\\n\");\n"
"\t\t\treturn 1;\n"
"\t}\n"
"\n"
"\treturn 0;\n"
"}\n"
"```"
msgstr ""
#: src/why-rust/an-example-in-c.md:48
msgid "How many bugs do you spot?"
msgstr "你发现了多少 bug?"
#: src/why-rust/an-example-in-c.md:52
msgid ""
"Despite just 29 lines of code, this C example contains serious bugs in at "
"least 11:"
msgstr "尽管该 C 语言示例仅有29行代码,但它却包含了至少11个严重 bug:"
#: src/why-rust/an-example-in-c.md:54
msgid "Assignment `=` instead of equality comparison `==` (line 28)"
msgstr "使用赋值 `=` 而非判断相等 `==`(第28行)"
#: src/why-rust/an-example-in-c.md:55
msgid "Excess argument to `printf` (line 23)"
msgstr "`printf` 有多余参数(第23行)"
#: src/why-rust/an-example-in-c.md:56
msgid "File descriptor leak (after line 26)"
msgstr "文件描述符泄露(第26行之后)"
#: src/why-rust/an-example-in-c.md:57
msgid "Forgotten braces in multi-line `if` (line 22)"
msgstr "多行 `if` 语句缺少花括号(第22行)"
#: src/why-rust/an-example-in-c.md:58
msgid "Forgotten `break` in a `switch` statement (line 32)"
msgstr "`switch` 语句忘记添加 `break`(第32行)"
#: src/why-rust/an-example-in-c.md:59
msgid ""
"Forgotten NUL-termination of the `buf` string, leading to a buffer overflow "
"(line 29)"
msgstr "`buf` 字符串忘记NUL终止符,从而导致缓冲区溢出(第29行)"
#: src/why-rust/an-example-in-c.md:60
msgid "Memory leak by not freeing the `malloc`\\-allocated buffer (line 21)"
msgstr "未释放由 `malloc` 分配的缓冲区,从而导致内存泄漏(第21行)"
#: src/why-rust/an-example-in-c.md:61
msgid "Out-of-bounds access (line 17)"
msgstr "越界访问(第17行)"
#: src/why-rust/an-example-in-c.md:62
msgid "Unchecked cases in the `switch` statement (line 11)"
msgstr "`switch` 语句存在未检查的情况(第11行)"
#: src/why-rust/an-example-in-c.md:63
msgid "Unchecked return values of `stat` and `fopen` (lines 18 and 26)"
msgstr "`stat` 和 `fopen` 存在未检查的返回值(第18行及第26行)"
#: src/why-rust/an-example-in-c.md:65
msgid ""
"_Shouldn't these bugs be obvious even for a C compiler?_ \n"
"No, surprisingly this code compiles warning-free at the default warning "
"level, even in the latest GCC version (13.2 as of writing)."
msgstr ""
"_即使对于 C 语言编译器,这些bug难道不应该是显而易见的吗?_ \n"
"惊人的是,即便使用最新版本的GCC(截至撰文时为13.2),在默认警告等级下编译代码"
"时也不出现任何警告。"
#: src/why-rust/an-example-in-c.md:68
msgid ""
"_Isn't this a highly unrealistic example?_ \n"
"Absolutely not, these kind of bugs have lead to serious security "
"vulnerabilities in the past. Some examples:"
msgstr ""
"_这是非常极端的示例吗?_ \n"
"当然不是。这些类型的bug在过去曾引发一系列的安全漏洞,比如以下案例:"
#: src/why-rust/an-example-in-c.md:71
msgid ""
"Assignment `=` instead of equality comparison `==`: [The Linux Backdoor "
"Attempt of 2003](https://freedom-to-tinker.com/2013/10/09/the-linux-backdoor-"
"attempt-of-2003)"
msgstr ""
"使用赋值 `=` 而非判断相等 `==`:[2003年Linux后门尝试](https://freedom-to-"
"tinker.com/2013/10/09/the-linux-backdoor-attempt-of-2003)"
#: src/why-rust/an-example-in-c.md:72
msgid ""
"Forgotten braces in multi-line `if`: [The Apple goto fail vulnerability]"
"(https://dwheeler.com/essays/apple-goto-fail.html)"
msgstr ""
"多行 `if` 语句缺少花括号:[Apple goto失败漏洞](https://dwheeler.com/essays/"
"apple-goto-fail.html)"
#: src/why-rust/an-example-in-c.md:73
msgid ""
"Forgotten `break` in a `switch` statement: [The break that broke sudo]"
"(https://nakedsecurity.sophos.com/2012/05/21/anatomy-of-a-security-hole-the-"
"break-that-broke-sudo)"
msgstr ""
"`switch` 语句忘记添加 `break`:[破坏sudo的break](https://nakedsecurity."
"sophos.com/2012/05/21/anatomy-of-a-security-hole-the-break-that-broke-sudo)"
#: src/why-rust/an-example-in-c.md:75
msgid ""
"_How is Rust any better here?_ \n"
"Safe Rust makes all of these bugs impossible:"
msgstr ""
"_Rust在这些方面表现得怎么样?_ \n"
"安全Rust使这些bug的出现变得不可能:"
#: src/why-rust/an-example-in-c.md:78
msgid "Assignments inside an `if` clause are not supported."
msgstr "不支持 `if` 语句内赋值。"
#: src/why-rust/an-example-in-c.md:79
msgid "Format strings are checked at compile-time."
msgstr "编译时检查格式化字符串。"
#: src/why-rust/an-example-in-c.md:80
msgid "Resources are freed at the end of scope via the `Drop` trait."
msgstr "在作用域末尾,Rust通过 `Drop` trait 来释放资源。"
#: src/why-rust/an-example-in-c.md:81
msgid "All `if` clauses require braces."
msgstr "所有 `if` 语句必须有花括号。"
#: src/why-rust/an-example-in-c.md:82
msgid ""
"`match` (as the Rust equivalent to `switch`) does not fall-through, hence "
"you can't accidentally forget a `break`."
msgstr ""
"`match` 语句(在 Rust 中相当于 `switch`)并不会落空,因此你不会意外忘记一个 "
"`break`。"
#: src/why-rust/an-example-in-c.md:83
msgid "Buffer slices carry their size and don't rely on a NUL terminator."
msgstr "缓冲区切片自带它们的大小,且不依赖NUL终止符。"
#: src/why-rust/an-example-in-c.md:84
msgid ""
"Heap-allocated memory is freed via the `Drop` trait when the corresponding "
"`Box` leaves the scope."
msgstr "当相关 `Box` 离开作用域时,Rust 通过 `Drop` trait 释放堆分配内存。"
#: src/why-rust/an-example-in-c.md:85
msgid ""
"Out-of-bounds accesses cause a panic or can be checked via the `get` method "
"of a slice."
msgstr ""
"越界访问会导致程序发生 panic 而终止,也可以用 `get` 方法来检查一个序列是否越"
"界。"
#: src/why-rust/an-example-in-c.md:86
msgid "`match` mandates that all cases are handled."
msgstr "`match` 语句规定要处理所有情况。"
#: src/why-rust/an-example-in-c.md:87
msgid ""
"Fallible Rust functions return `Result` values that need to be unwrapped and "
"thereby checked for success. Additionally, the compiler emits a warning if "
"you miss to check the return value of a function marked with `#[must_use]`."
msgstr ""
"可出错的 Rust 函数返回的 `Result` 值需要拆箱并检查是否成功。此外,如果你忽略"
"检查标注为 `#[must_use]` 的函数的返回值,编译器会发出警告。"
#: src/why-rust/compile-time.md:3
msgid "Static memory management at compile time:"
msgstr "编译期静态内存管理:"
#: src/why-rust/compile-time.md:5
msgid "No uninitialized variables."
msgstr "不存在未初始化的变量。"
#: src/why-rust/compile-time.md:6
msgid "No memory leaks (_mostly_, see notes)."
msgstr "不存在内存泄漏(_通常情况下_,见注释)。"
#: src/why-rust/compile-time.md:7
msgid "No double-frees."
msgstr "不存在“双重释放”。"
#: src/why-rust/compile-time.md:8
msgid "No use-after-free."
msgstr "不存在“释放后使用”。"
#: src/why-rust/compile-time.md:9
msgid "No `NULL` pointers."
msgstr "不存在 `NULL` 指针。"
#: src/why-rust/compile-time.md:10
msgid "No forgotten locked mutexes."
msgstr "不存在被遗忘的互斥锁。"
#: src/why-rust/compile-time.md:11
msgid "No data races between threads."
msgstr "不存在线程之间的数据竞争。"
#: src/why-rust/compile-time.md:12
msgid "No iterator invalidation."
msgstr "不存在迭代器失效。"
#: src/why-rust/compile-time.md:16
msgid ""
"It is possible to produce memory leaks in (safe) Rust. Some examples are:"
msgstr "在(安全的)Rust 中也有可能产生内存泄漏。例如:"
#: src/why-rust/compile-time.md:19
msgid ""
"You can use [`Box::leak`](https://doc.rust-lang.org/std/boxed/struct.Box."
"html#method.leak) to leak a pointer. A use of this could be to get runtime-"
"initialized and runtime-sized static variables"
msgstr ""
"可以使用 [`Box::leak`](https://doc.rust-lang.org/std/boxed/struct.Box."
"html#method.leak) 来泄漏一个指针。该方法可以用于得到在运行时决定大小和初始化"
"的静态变量"
#: src/why-rust/compile-time.md:21
msgid ""
"You can use [`std::mem::forget`](https://doc.rust-lang.org/std/mem/fn.forget."
"html) to make the compiler \"forget\" about a value (meaning the destructor "
"is never run)."
msgstr ""
"可以使用 [`std::mem::forget`](https://doc.rust-lang.org/std/mem/fn.forget."
"html) 来让编译器“忘记”一个值(即其析构函数不会被执行)。"
#: src/why-rust/compile-time.md:23
msgid ""
"You can also accidentally create a [reference cycle](https://doc.rust-lang."
"org/book/ch15-06-reference-cycles.html) with `Rc` or `Arc`."
msgstr ""
"可以使用 `Rc` 或 `Arc` 意外创建一个循环引用([reference cycle](https://doc."
"rust-lang.org/book/ch15-06-reference-cycles.html))。"
#: src/why-rust/compile-time.md:25
msgid ""
"In fact, some will consider infinitely populating a collection a memory leak "
"and Rust does not protect from those."
msgstr ""
"实际上,有人认为无限填充一个集合也是一种内存泄漏,而 Rust 对此没有保护。"
#: src/why-rust/compile-time.md:28
msgid ""
"For the purpose of this course, \"No memory leaks\" should be understood as "
"\"Pretty much no _accidental_ memory leaks\"."
msgstr "就本课程而言,“不存在内存泄漏”应理解为“几乎没有 _意外_ 内存泄漏”。"
#: src/why-rust/runtime.md:3
msgid "No undefined behavior at runtime:"
msgstr "Rust 没有运行时未定义行为:"
#: src/why-rust/runtime.md:5
msgid "Array access is bounds checked."
msgstr "数组访问有边界检查。"
#: src/why-rust/runtime.md:6
msgid "Integer overflow is defined (panic or wrap-around)."
msgstr "整数溢出有明确定义(panic 或回绕)。"
#: src/why-rust/runtime.md:12
msgid ""
"Integer overflow is defined via the [`overflow-checks`](https://doc.rust-"
"lang.org/rustc/codegen-options/index.html#overflow-checks) compile-time "
"flag. If enabled, the program will panic (a controlled crash of the "
"program), otherwise you get wrap-around semantics. By default, you get "
"panics in debug mode (`cargo build`) and wrap-around in release mode (`cargo "
"build --release`)."
msgstr ""
"整数溢出的行为由编译时的标志指定。可以选择 panic(一种受控的程序崩溃)或使"
"用“回绕(wrap-around)”语义。默认情况下,使用调试模式编译(`cargo build`)的"
"行为为 panic,使用发布模式编译(`cargo build --release`)的行为为“回绕”。"
#: src/why-rust/runtime.md:18
msgid ""
"Bounds checking cannot be disabled with a compiler flag. It can also not be "
"disabled directly with the `unsafe` keyword. However, `unsafe` allows you to "
"call functions such as `slice::get_unchecked` which does not do bounds "
"checking."
msgstr ""
"边界检查不能使用编译标志禁用,也不能直接通过 `unsafe` 关键字禁用。然而, "
"`unsafe` 允许你调用 `slice::get_unchecked` 等不做边界检查的函数。"
#: src/why-rust/modern.md:3
msgid "Rust is built with all the experience gained in the last decades."
msgstr "Rust 建立于过去几十年来所获得的经验之上。"
#: src/why-rust/modern.md:5
msgid "Language Features"
msgstr "语言特性"
#: src/why-rust/modern.md:7
msgid "Enums and pattern matching."
msgstr "枚举和模式匹配。"
#: src/why-rust/modern.md:8
msgid "Generics."
msgstr "泛型。"
#: src/why-rust/modern.md:9
msgid "No overhead FFI."
msgstr "无额外开销的外部函数接口(FFI)。"
#: src/why-rust/modern.md:10
msgid "Zero-cost abstractions."
msgstr "零成本抽象。"
#: src/why-rust/modern.md:12
msgid "Tooling"
msgstr "工具"
#: src/why-rust/modern.md:14
msgid "Great compiler errors."
msgstr "强大的编译器错误提示。"
#: src/why-rust/modern.md:15
msgid "Built-in dependency manager."
msgstr "内置依赖管理器。"
#: src/why-rust/modern.md:16
msgid "Built-in support for testing."
msgstr "对测试的内置支持。"
#: src/why-rust/modern.md:17
msgid "Excellent Language Server Protocol support."
msgstr "优秀的语言服务协议(Language Server Protocol)支持。"
#: src/why-rust/modern.md:23
msgid ""
"Zero-cost abstractions, similar to C++, means that you don't have to 'pay' "
"for higher-level programming constructs with memory or CPU. For example, "
"writing a loop using `for` should result in roughly the same low level "
"instructions as using the `.iter().fold()` construct."
msgstr ""
"与 C++ 类似的零成本抽象,意味着你不需要为高级程序语言的结构“付出”更多的内存"
"和 CPU。例如使用 `for` 循环与使用 `.iter().fold()` 结构应该会生成大致相同的底"
"层指令。"
#: src/why-rust/modern.md:28
msgid ""
"It may be worth mentioning that Rust enums are 'Algebraic Data Types', also "
"known as 'sum types', which allow the type system to express things like "
"`Option` and `Result`."
msgstr ""
"值得一提的是,Rust 的枚举是“代数数据类型”(也叫“和类型”)。它使得类型系统可以"
"表示 `Option` 和 `Result` 等结构。"
#: src/why-rust/modern.md:32
msgid ""
"Remind people to read the errors --- many developers have gotten used to "
"ignore lengthy compiler output. The Rust compiler is significantly more "
"talkative than other compilers. It will often provide you with _actionable_ "
"feedback, ready to copy-paste into your code."
msgstr ""
"提醒学生去阅读编译错误 --- 许多开发者已经习惯去忽略冗长的编译器输出。Rust 编"
"译器会比其它编译器更健谈。它通常会提供 _可操作的_ 反馈,可以直接复制粘贴到代"
"码中。"
#: src/why-rust/modern.md:37
msgid ""
"The Rust standard library is small compared to languages like Java, Python, "
"and Go. Rust does not come with several things you might consider standard "
"and essential:"
msgstr ""
"相比 Java、Python 和 Go 等语言,Rust 标准库较为精简。Rust 并没有内置一些你可"
"能认为标准和必要的功能:"
#: src/why-rust/modern.md:41
msgid "a random number generator, but see [rand](https://docs.rs/rand/)."
msgstr "随机数生成器,可以使用 [rand](https://docs.rs/rand/) 替代。"
#: src/why-rust/modern.md:42
msgid "support for SSL or TLS, but see [rusttls](https://docs.rs/rustls/)."
msgstr "SSL 和 TLS 支持,可以使用 [rusttls](https://docs.rs/rustls/) 替代。"
#: src/why-rust/modern.md:43
msgid "support for JSON, but see [serde_json](https://docs.rs/serde_json/)."
msgstr "JSON 支持,可以使用 [serde_json](https://docs.rs/serde_json/) 替代。"
#: src/why-rust/modern.md:45
msgid ""
"The reasoning behind this is that functionality in the standard library "
"cannot go away, so it has to be very stable. For the examples above, the "
"Rust community is still working on finding the best solution --- and perhaps "
"there isn't a single \"best solution\" for some of these things."
msgstr ""
"Rust 这么做的原因是标准库中的功能是无法去除的,因此该功能必须非常稳定。对于以"
"上例子,Rust 社区仍在寻找最佳解决方案 --- 甚至对一些情况可能没有单一的“最佳解"
"决方案”。"
#: src/why-rust/modern.md:50
msgid ""
"Rust comes with a built-in package manager in the form of Cargo and this "
"makes it trivial to download and compile third-party crates. A consequence "
"of this is that the standard library can be smaller."
msgstr ""
"Rust 内置了一个包管理器 Cargo,使得下载和编译第三方 crate 变得简单。这也导致"
"标准库可以更加精简。"
#: src/why-rust/modern.md:54
msgid ""
"Discovering good third-party crates can be a problem. Sites like help with this by letting you compare health metrics for crates to "
"find a good and trusted one."
msgstr ""
"发现高质量的第三方 crate 也许是一个问题。 等网站对此问题有"
"所帮助。它能帮你比较 crate 的健康指标,以找到一个高质量并受信任的 crate。"
#: src/why-rust/modern.md:58
msgid ""
"[rust-analyzer](https://rust-analyzer.github.io/) is a well supported LSP "
"implementation used in major IDEs and text editors."
msgstr ""
"[rust-analyzer](https://rust-analyzer.github.io/) 是一个受到广泛支持的 LSP 实"
"现,被主流的 IDE 和文本编辑器所使用。"
#: src/basic-syntax.md:3
msgid "Much of the Rust syntax will be familiar to you from C, C++ or Java:"
msgstr "Rust 的许多语法与 C、C++ 和 Java 的语法相似:"
#: src/basic-syntax.md:5
msgid "Blocks and scopes are delimited by curly braces."
msgstr "代码块和作用域都是由花括号来界定的。"
#: src/basic-syntax.md:6
msgid ""
"Line comments are started with `//`, block comments are delimited by `/* ... "
"*/`."
msgstr "行内注释以 `//` 起始,块注释使用 `/* ... */` 来界定。"
#: src/basic-syntax.md:8
msgid "Keywords like `if` and `while` work the same."
msgstr "`if` 和 `while` 等关键词作用与以上语言一致。"
#: src/basic-syntax.md:9
msgid "Variable assignment is done with `=`, comparison is done with `==`."
msgstr "变量赋值使用 `=`,值之间比较使用 `==`。"
#: src/basic-syntax/scalar-types.md:3 src/basic-syntax/compound-types.md:3
#: src/exercises/day-3/safe-ffi-wrapper.md:16
msgid "Types"
msgstr "类型"
#: src/basic-syntax/scalar-types.md:3 src/basic-syntax/compound-types.md:3
msgid "Literals"
msgstr "字面量"
#: src/basic-syntax/scalar-types.md:5
msgid "Signed integers"
msgstr "有符号整数"
#: src/basic-syntax/scalar-types.md:5
msgid "`i8`, `i16`, `i32`, `i64`, `i128`, `isize`"
msgstr "`i8`、`i16`、`i32`、`i64`、`i128`、`isize`"
#: src/basic-syntax/scalar-types.md:5
msgid "`-10`, `0`, `1_000`, `123_i64`"
msgstr "`-10`、`0`、`1_000`、`123_i64`"
#: src/basic-syntax/scalar-types.md:6
msgid "Unsigned integers"
msgstr "无符号整数"
#: src/basic-syntax/scalar-types.md:6
msgid "`u8`, `u16`, `u32`, `u64`, `u128`, `usize`"
msgstr "`u8`、`u16`、`u32`、`u64`、`u128`、`usize`"
#: src/basic-syntax/scalar-types.md:6
msgid "`0`, `123`, `10_u16`"
msgstr "`0`、`123`、`10_u16`"
#: src/basic-syntax/scalar-types.md:7
msgid "Floating point numbers"
msgstr "浮点数"
#: src/basic-syntax/scalar-types.md:7
msgid "`f32`, `f64`"
msgstr "`f32`、`f64`"
#: src/basic-syntax/scalar-types.md:7
msgid "`3.14`, `-10.0e20`, `2_f32`"
msgstr "`3.14`、`-10.0e20`、`2_f32`"
#: src/basic-syntax/scalar-types.md:8
msgid "Strings"
msgstr "字符串"
#: src/basic-syntax/scalar-types.md:8
msgid "`&str`"
msgstr "`&str`"
#: src/basic-syntax/scalar-types.md:8
msgid "`\"foo\"`, `\"two\\nlines\"`"
msgstr "`\"foo\"`、`“两\\n行”`"
#: src/basic-syntax/scalar-types.md:9
msgid "Unicode scalar values"
msgstr "Unicode 标量类型"
#: src/basic-syntax/scalar-types.md:9
msgid "`char`"
msgstr "`char`"
#: src/basic-syntax/scalar-types.md:9
msgid "`'a'`, `'α'`, `'∞'`"
msgstr "`'a'`、`'α'`、`'∞'`"
#: src/basic-syntax/scalar-types.md:10
msgid "Booleans"
msgstr "布尔值"
#: src/basic-syntax/scalar-types.md:10
msgid "`bool`"
msgstr "`bool`"
#: src/basic-syntax/scalar-types.md:10
msgid "`true`, `false`"
msgstr "`true`、`false`"
#: src/basic-syntax/scalar-types.md:12
msgid "The types have widths as follows:"
msgstr "各类型占用的空间为:"
#: src/basic-syntax/scalar-types.md:14
msgid "`iN`, `uN`, and `fN` are _N_ bits wide,"
msgstr "`iN`, `uN` 和 `fN` 占用 _N_ 位,"
#: src/basic-syntax/scalar-types.md:15
msgid "`isize` and `usize` are the width of a pointer,"
msgstr "`isize` 和 `usize` 占用一个指针大小的空间,"
#: src/basic-syntax/scalar-types.md:16
msgid "`char` is 32 bits wide,"
msgstr "`char` 占用 32 位空间,"
#: src/basic-syntax/scalar-types.md:17
msgid "`bool` is 8 bits wide."
msgstr "`bool` 占用 8 位空间。"
#: src/basic-syntax/scalar-types.md:21
msgid "There are a few syntaxes which are not shown above:"
msgstr "上表中还有一些未提及的语法:"
#: src/basic-syntax/scalar-types.md:23
msgid ""
"Raw strings allow you to create a `&str` value with escapes disabled: "
"`r\"\\n\" == \"\\\\n\"`. You can embed double-quotes by using an equal "
"amount of `#` on either side of the quotes:"
msgstr ""
"原始字符串可在创建 `&str` 时禁用转义:`r\"\\n\" == \"\\\\n\"`。可以在外层引号"
"两侧添加相同数量的 `#`,以在字符串中嵌入双引号:"
#: src/basic-syntax/scalar-types.md:35
msgid "Byte strings allow you to create a `&[u8]` value directly:"
msgstr "字节串可以用于直接创建 `&[u8]` 类型的值:"
#: src/basic-syntax/scalar-types.md:45
msgid ""
"All underscores in numbers can be left out, they are for legibility only. So "
"`1_000` can be written as `1000` (or `10_00`), and `123_i64` can be written "
"as `123i64`."
msgstr ""
"数字中的所有下划线均可忽略,它们只是为了方便辨识。因此,`1_000` 可以写为 "
"`1000`(或 `10_00`),而 `123_i64` 可以写为 `123i64`。"
#: src/basic-syntax/compound-types.md:5
msgid "Arrays"
msgstr "数组(Arrays)"
#: src/basic-syntax/compound-types.md:5
msgid "`[T; N]`"
msgstr "`[T; N]`"
#: src/basic-syntax/compound-types.md:5
msgid "`[20, 30, 40]`, `[0; 3]`"
msgstr "`[20, 30, 40]`, `[0; 3]`"
#: src/basic-syntax/compound-types.md:6
msgid "Tuples"
msgstr "元组(Tuples)"
#: src/basic-syntax/compound-types.md:6
msgid "`()`, `(T,)`, `(T1, T2)`, ..."
msgstr "`()`, `(T,)`, `(T1, T2)`, ..."
#: src/basic-syntax/compound-types.md:6
msgid "`()`, `('x',)`, `('x', 1.2)`, ..."
msgstr "`()`, `('x',)`, `('x', 1.2)`, ..."
#: src/basic-syntax/compound-types.md:8
msgid "Array assignment and access:"
msgstr "数组的赋值和访问操作:"
#: src/basic-syntax/compound-types.md:19
msgid "Tuple assignment and access:"
msgstr "元组的赋值和访问操作:"
#: src/basic-syntax/compound-types.md:34
msgid "Arrays:"
msgstr "数组:"
#: src/basic-syntax/compound-types.md:36
#, fuzzy
msgid ""
"A value of the array type `[T; N]` holds `N` (a compile-time constant) "
"elements of the same type `T`. Note that the length of the array is _part of "
"its type_, which means that `[u8; 3]` and `[u8; 4]` are considered two "
"different types."
msgstr ""
"数组中的元素具有相同的类型 `T`,数组的长度为 `N`,`N` 是一个编译期常量。 需要"
"注意的是数组的长度是它_类型的一部分\\_, 这意味着 `[u8; 3]` 和 `[u8; 4]` 在 "
"Rust 中被认为是不同的类型。"
#: src/basic-syntax/compound-types.md:40
msgid "We can use literals to assign values to arrays."
msgstr "我们可以使用字面量来为数组赋值。"
#: src/basic-syntax/compound-types.md:42
msgid ""
"In the main function, the print statement asks for the debug implementation "
"with the `?` format parameter: `{}` gives the default output, `{:?}` gives "
"the debug output. We could also have used `{a}` and `{a:?}` without "
"specifying the value after the format string."
msgstr ""
"在主函数中,打印(print)语句使用 `?` 格式请求调试实现。 使用参数 `{}` 打印默"
"认输出,`{:?}` 表示以调试格式输出。 我们也可以不在格式化字符串后面指定变量"
"值,直接使用 `{a}` 和 `{a:?}` 进行输出。"
#: src/basic-syntax/compound-types.md:47
msgid ""
"Adding `#`, eg `{a:#?}`, invokes a \"pretty printing\" format, which can be "
"easier to read."
msgstr ""
"添加 `#`,比如 `{a:#?}`,会输出“美观打印(pretty printing)” 格式,这种格式可"
"能会更加易读。"
#: src/basic-syntax/compound-types.md:49
msgid "Tuples:"
msgstr "元组:"
#: src/basic-syntax/compound-types.md:51
msgid "Like arrays, tuples have a fixed length."
msgstr "和数组一样,元组也具有固定的长度。"
#: src/basic-syntax/compound-types.md:53
msgid "Tuples group together values of different types into a compound type."
msgstr "元组将不同类型的值组成一个复合类型。"
#: src/basic-syntax/compound-types.md:55
msgid ""
"Fields of a tuple can be accessed by the period and the index of the value, "
"e.g. `t.0`, `t.1`."
msgstr "元组中的字段可以通过英文句号加上值的下标进行访问比如:`t.0`, `t.1`。"
#: src/basic-syntax/compound-types.md:57
msgid ""
"The empty tuple `()` is also known as the \"unit type\". It is both a type, "
"and the only valid value of that type - that is to say both the type and its "
"value are expressed as `()`. It is used to indicate, for example, that a "
"function or expression has no return value, as we'll see in a future slide. "
msgstr ""
"空元组 `()` 也被称作 “单元(unit)类型”. 它既是一个类型, 也是这种类型的唯一"
"值——也就是说它的类型和它的值都被表示为 `()`。它通常用于表示,比如,一个函数或"
"表达式没有返回值,我们会在后续的幻灯片种见到这种用法。"
#: src/basic-syntax/compound-types.md:61
msgid ""
"You can think of it as `void` that can be familiar to you from other "
"programming languages."
msgstr "你可以将其理解为你可能在其他编程语言中比较熟悉的 `void` 类型。"
#: src/basic-syntax/references.md:3
msgid "Like C++, Rust has references:"
msgstr "如同 C++ 一样,Rust 也提供了引用类型。"
#: src/basic-syntax/references.md:15
msgid "Some notes:"
msgstr "一些注意事项:"
#: src/basic-syntax/references.md:17
msgid ""
"We must dereference `ref_x` when assigning to it, similar to C and C++ "
"pointers."
msgstr ""
"就像 C 与 C++ 中的指针一样,对引用 `ref_x` 进行赋值时,我们必须对其解引用。"
#: src/basic-syntax/references.md:18
msgid ""
"Rust will auto-dereference in some cases, in particular when invoking "
"methods (try `ref_x.count_ones()`)."
msgstr ""
"Rust 有时会进行自动解引用。比如调用方法 `ref_x.count_ones()` 时,ref_x 会被解"
"引用。"
#: src/basic-syntax/references.md:20
msgid ""
"References that are declared as `mut` can be bound to different values over "
"their lifetime."
msgstr ""
"如果引用值被声明为 `mut`(可变引用),那么这个引用值可以在它的生命周期内被绑"
"定为不同的值。"
#: src/basic-syntax/references.md:26
msgid ""
"Be sure to note the difference between `let mut ref_x: &i32` and `let ref_x: "
"&mut i32`. The first one represents a mutable reference which can be bound "
"to different values, while the second represents a reference to a mutable "
"value."
msgstr ""
"注意 `let mut ref_x: &i32` 与 `let ref_x: &mut i32` 之间的区别。第一条语句声"
"明了一个可变引用,所以我们可以修改这个引用所绑定的值;第二条语句声明了一个指"
"向可变变量的引用。"
#: src/basic-syntax/references-dangling.md:3
msgid "Rust will statically forbid dangling references:"
msgstr "Rust 会静态禁止悬垂引用:"
#: src/basic-syntax/references-dangling.md:17
msgid "A reference is said to \"borrow\" the value it refers to."
msgstr "一个引用被认为是“借用(borrow)”了它指向的值。"
#: src/basic-syntax/references-dangling.md:18
msgid ""
"Rust is tracking the lifetimes of all references to ensure they live long "
"enough."
msgstr "Rust 会跟踪所有引用的生命周期,以确保这些值的存活时间足够长。"
#: src/basic-syntax/references-dangling.md:20
msgid "We will talk more about borrowing when we get to ownership."
msgstr "我们会在讲到所有权(ownership)时详细讨论借用(borrow)。"
#: src/basic-syntax/slices.md:3
msgid "A slice gives you a view into a larger collection:"
msgstr "切片 (slice) 的作用是提供对集合 (collection) 的视图 (view):"
#: src/basic-syntax/slices.md:17
msgid "Slices borrow data from the sliced type."
msgstr "切片从被切片的类型中借用 (borrow) 数据。"
#: src/basic-syntax/slices.md:18
#, fuzzy
msgid "Question: What happens if you modify `a[3]` right before printing `s`?"
msgstr "请思考:如果我们改变 `a[3]`,将会产生怎样的后果?"
#: src/basic-syntax/slices.md:22
#, fuzzy
msgid ""
"We create a slice by borrowing `a` and specifying the starting and ending "
"indexes in brackets."
msgstr "创建切片时,我们借用了 `a` ,并在方括号中标明了起始和结尾下标。"
#: src/basic-syntax/slices.md:24
#, fuzzy
msgid ""
"If the slice starts at index 0, Rust’s range syntax allows us to drop the "
"starting index, meaning that `&a[0..a.len()]` and `&a[..a.len()]` are "
"identical."
msgstr ""
"如果切片的起始下标为 0, Rust 语法允许我们省略起始下标。比如说 `&a[0..a."
"len()]` 与 `&a[..a.len()]` 是等价的。"
#: src/basic-syntax/slices.md:26
#, fuzzy
msgid ""
"The same is true for the last index, so `&a[2..a.len()]` and `&a[2..]` are "
"identical."
msgstr ""
"结尾下标也可以用相同方式省略。比如说 `&a[2..a.len()]` 和 `&a[2..]` 是等价的。"
#: src/basic-syntax/slices.md:28
#, fuzzy
msgid ""
"To easily create a slice of the full array, we can therefore use `&a[..]`."
msgstr "因此,我们可以用 `&a[..]` 来创建包含整个数组的切片。"
#: src/basic-syntax/slices.md:30
#, fuzzy
msgid ""
"`s` is a reference to a slice of `i32`s. Notice that the type of `s` "
"(`&[i32]`) no longer mentions the array length. This allows us to perform "
"computation on slices of different sizes."
msgstr ""
"切片会从另外一个对象中借用数据。在这个例子中, `a` 必须在其切片存活时保持存活"
"(处于作用域中)。"
#: src/basic-syntax/slices.md:32
#, fuzzy
msgid ""
"Slices always borrow from another object. In this example, `a` has to remain "
"'alive' (in scope) for at least as long as our slice. "
msgstr ""
"关于修改 `a[3]` 的问题可能会引发精彩的讨论。正确答案是:为了保证内存安全,在"
"创建切片后,我们不能通过 `a` 来修改数据。不过我们可以通过 `a` 或者 `s` 来读取"
"数据。我们将会在“借用”章节着重介绍这个内容。"
#: src/basic-syntax/slices.md:34
msgid ""
"The question about modifying `a[3]` can spark an interesting discussion, but "
"the answer is that for memory safety reasons you cannot do it through `a` at "
"this point in the execution, but you can read the data from both `a` and `s` "
"safely. It works before you created the slice, and again after the "
"`println`, when the slice is no longer used. More details will be explained "
"in the borrow checker section."
msgstr ""
"关于修改“a\\[3\\]”的问题可能会引发一些有趣的讨论,但正解是,出于内存安全方面"
"的原因,您无法在执行作业的这个时间点通过“a”来进行此修改,但可以从“a”和“s”安全"
"地读取数据。它会在您创建 Slice 之前运作,在“println”之后(不再使用 Slice 时)"
"再次运作。更多详情会在“借用检查器”部分中加以说明。"
#: src/basic-syntax/string-slices.md:1
msgid "`String` vs `str`"
msgstr "“String”与“str”的区别"
#: src/basic-syntax/string-slices.md:3
msgid "We can now understand the two string types in Rust:"
msgstr "现在我们就可以理解 Rust 中的两种字符串类型:"
#: src/basic-syntax/string-slices.md:5
msgid ""
"```rust,editable\n"
"fn main() {\n"
" let s1: &str = \"World\";\n"
" println!(\"s1: {s1}\");\n"
"\n"
" let mut s2: String = String::from(\"Hello \");\n"
" println!(\"s2: {s2}\");\n"
" s2.push_str(s1);\n"
" println!(\"s2: {s2}\");\n"
" \n"
" let s3: &str = &s2[6..];\n"
" println!(\"s3: {s3}\");\n"
"}\n"
"```"
msgstr ""
#: src/basic-syntax/string-slices.md:20
msgid "Rust terminology:"
msgstr "Rust 术语:"
#: src/basic-syntax/string-slices.md:22
msgid "`&str` an immutable reference to a string slice."
msgstr "`&str` 是一个指向字符串片段的不可变引用。"
#: src/basic-syntax/string-slices.md:23
msgid "`String` a mutable string buffer."
msgstr "`String` 是一个可变字符串缓冲区。"
#: src/basic-syntax/string-slices.md:27
msgid ""
"`&str` introduces a string slice, which is an immutable reference to UTF-8 "
"encoded string data stored in a block of memory. String literals "
"(`”Hello”`), are stored in the program’s binary."
msgstr ""
"`&str` 引入了一个字符串切片,它是一个指向保存在内存块中的 UTF-8 编码字符串数"
"据的不可变引用。 字符串字面量(`”Hello”`)会保存在程序的二进制文件中。"
#: src/basic-syntax/string-slices.md:30
msgid ""
"Rust’s `String` type is a wrapper around a vector of bytes. As with a "
"`Vec`, it is owned."
msgstr ""
"Rust 的 `String` 类型是一个字节 vector 的封装。和 `Vec` 一样,它是拥有所有"
"权的。"
#: src/basic-syntax/string-slices.md:32
msgid ""
"As with many other types `String::from()` creates a string from a string "
"literal; `String::new()` creates a new empty string, to which string data "
"can be added using the `push()` and `push_str()` methods."
msgstr ""
"和其他类型一样,`String::from()` 会从字符串字面量创建一个字符串;`String::"
"new()` 会创建一个新的空字符串, 之后可以使用 `push()` 和 `push_str()` 方法"
"向其中添加字符串数据。"
#: src/basic-syntax/string-slices.md:35
msgid ""
"The `format!()` macro is a convenient way to generate an owned string from "
"dynamic values. It accepts the same format specification as `println!()`."
msgstr ""
"`format!()` 宏可以方便地动态生成拥有所有权的字符串。它接受和 `println!()` 相"
"同的格式规范。"
#: src/basic-syntax/string-slices.md:38
msgid ""
"You can borrow `&str` slices from `String` via `&` and optionally range "
"selection."
msgstr "你可以通过 `&` 和可选的范围选择从 `String` 中借用 `&str` 切片。"
#: src/basic-syntax/string-slices.md:40
msgid ""
"For C++ programmers: think of `&str` as `const char*` from C++, but the one "
"that always points to a valid string in memory. Rust `String` is a rough "
"equivalent of `std::string` from C++ (main difference: it can only contain "
"UTF-8 encoded bytes and will never use a small-string optimization)."
msgstr ""
"对于 C++ 程序员:可以把 `&str` 当作 C++ 中的 `const char*`,但是它总是指向内"
"存中的一个有效字符串。 Rust 的 `String` 大致相当于 C++ 中 `std::string` "
"(主要区别:它只能包含 UTF-8 编码的字节, 并且永远不会使用小字符串优化"
"(small-string optimization))。"
#: src/basic-syntax/functions.md:3
msgid ""
"A Rust version of the famous [FizzBuzz](https://en.wikipedia.org/wiki/"
"Fizz_buzz) interview question:"
msgstr ""
"一个 Rust 版本的著名 [FizzBuzz](https://en.wikipedia.org/wiki/Fizz_buzz) 面试"
"题:"
#: src/basic-syntax/functions.md:36
msgid ""
"We refer in `main` to a function written below. Neither forward declarations "
"nor headers are necessary. "
msgstr ""
"我们在 `main` 中引用了下面编写的一个函数。不需要提前声明或添加头文件。 "
#: src/basic-syntax/functions.md:37
msgid ""
"Declaration parameters are followed by a type (the reverse of some "
"programming languages), then a return type."
msgstr "类型跟随在声明的参数后(与某些编程语言相反),然后是返回类型。"
#: src/basic-syntax/functions.md:38
msgid ""
"The last expression in a function body (or any block) becomes the return "
"value. Simply omit the `;` at the end of the expression."
msgstr ""
"函数体(或任何块)中的最后一个表达式将成为返回值。只需省略表达式末尾的 `;` 即"
"可。"
#: src/basic-syntax/functions.md:39
msgid ""
"Some functions have no return value, and return the 'unit type', `()`. The "
"compiler will infer this if the `-> ()` return type is omitted."
msgstr ""
"有些函数没有返回值,会返回“单元类型(unit type)”`()`。如果省略了`-> ()`的返"
"回类型,编译器将会自动推断。"
#: src/basic-syntax/functions.md:40
msgid ""
"The range expression in the `for` loop in `print_fizzbuzz_to()` contains "
"`=n`, which causes it to include the upper bound."
msgstr ""
"`print_fizzbuzz_to()`函数中`for`循环的范围表达式(range expression)包含"
"`=n`,这会导致它包括上限。"
#: src/basic-syntax/rustdoc.md:3
msgid ""
"All language items in Rust can be documented using special `///` syntax."
msgstr "Rust 中的所有语言元素都可以通过特殊的 `///` 语法进行文档化。"
#: src/basic-syntax/rustdoc.md:5
#, fuzzy
msgid ""
"```rust,editable\n"
"/// Determine whether the first argument is divisible by the second "
"argument.\n"
"///\n"
"/// If the second argument is zero, the result is false.\n"
"///\n"
"/// # Example\n"
"/// ```\n"
"/// assert!(is_divisible_by(42, 2));\n"
"/// ```\n"
"fn is_divisible_by(lhs: u32, rhs: u32) -> bool {\n"
" if rhs == 0 {\n"
" return false; // Corner case, early return\n"
" }\n"
" lhs % rhs == 0 // The last expression in a block is the return "
"value\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"/// 判断第一个参数是否可以被第二个参数整除。\n"
"///\n"
"/// 如果第二个参数是 0,则返回结果为 false。\n"
"fn is_divisible_by(lhs: u32, rhs: u32) -> bool {\n"
" if rhs == 0 {\n"
" return false; // 边界条件,直接返回\n"
" }\n"
" lhs % rhs == 0 // 代码块中的最后一个表达式就是它的返回值\n"
"}\n"
"```"
#: src/basic-syntax/rustdoc.md:22
#, fuzzy
msgid ""
"The contents are treated as Markdown. All published Rust library crates are "
"automatically documented at [`docs.rs`](https://docs.rs) using the [rustdoc]"
"(https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) tool. It is "
"idiomatic to document all public items in an API using this pattern. Code "
"snippets can document usage and will be used as unit tests."
msgstr ""
"文档的内容会被当做 Markdown 处理。所有已发布 Rust 库 crate 都会自动被"
"[rustdoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) 工具在 "
"[`docs.rs`](https://docs.rs)存档。 按照这种方式来为 API 中的所有公开项编写文"
"档是 Rust 中惯用的做法。"
#: src/basic-syntax/rustdoc.md:30
msgid ""
"Show students the generated docs for the `rand` crate at [`docs.rs/rand`]"
"(https://docs.rs/rand)."
msgstr ""
"向学生展示在 [`docs.rs/rand`](https://docs.rs/rand) 中为 `rand` crate 生成的"
"文档。"
#: src/basic-syntax/rustdoc.md:33
msgid ""
"This course does not include rustdoc on slides, just to save space, but in "
"real code they should be present."
msgstr ""
"本课程的幻灯片中不包含 rustdoc,这是为了节省空间,但是在实际的代码中,应当编"
"写相关的程序文档。"
#: src/basic-syntax/rustdoc.md:36
msgid ""
"Inner doc comments are discussed later (in the page on modules) and need not "
"be addressed here."
msgstr "内部文档注释将在稍后(在讲解模块的页面)讨论,这里无需进行说明。"
#: src/basic-syntax/rustdoc.md:39
msgid ""
"Rustdoc comments can contain code snippets that we can run and test using "
"`cargo test`. We will discuss these tests in the [Testing section](../"
"testing/doc-tests.html)."
msgstr ""
"Rustdoc 注释可以包含我们可使用“cargo test”运行和测试的代码段。我们将在[“测"
"试”部分](../testing/doc-tests.html)中讨论这些测试。"
#: src/basic-syntax/methods.md:3
msgid ""
"Methods are functions associated with a type. The `self` argument of a "
"method is an instance of the type it is associated with:"
msgstr ""
"方法是与某种类型关联的函数。方法的 `self` 参数是与其关联类型的一个实例:"
#: src/basic-syntax/methods.md:6
msgid ""
"```rust,editable\n"
"struct Rectangle {\n"
" width: u32,\n"
" height: u32,\n"
"}\n"
"\n"
"impl Rectangle {\n"
" fn area(&self) -> u32 {\n"
" self.width * self.height\n"
" }\n"
"\n"
" fn inc_width(&mut self, delta: u32) {\n"
" self.width += delta;\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
" let mut rect = Rectangle { width: 10, height: 5 };\n"
" println!(\"old area: {}\", rect.area());\n"
" rect.inc_width(5);\n"
" println!(\"new area: {}\", rect.area());\n"
"}\n"
"```"
msgstr ""
#: src/basic-syntax/methods.md:30
msgid ""
"We will look much more at methods in today's exercise and in tomorrow's "
"class."
msgstr "我们将在今天的练习和明天的课程中更深入地学习方法相关的概念。"
#: src/basic-syntax/methods.md:34
#, fuzzy
msgid "Add a static method called `Rectangle::new` and call this from `main`:"
msgstr "新增一个 `Rectangle::new` 构造函数并在 `main` 函数中调用它:"
#: src/basic-syntax/methods.md:42
msgid ""
"While _technically_, Rust does not have custom constructors, static methods "
"are commonly used to initialize structs (but don't have to). The actual "
"constructor, `Rectangle { width, height }`, could be called directly. See "
"the [Rustnomicon](https://doc.rust-lang.org/nomicon/constructors.html)."
msgstr ""
"虽然从技术层面来讲,Rust 没有自定义构造函数,但静态方法通常用于初始化结构体"
"(但并非必须这样做)。您可以直接调用实际构造函数“Rectangle { width, "
"height }”。请参阅 [Rust 秘典](https://doc.rust-lang.org/nomicon/constructors."
"html)。"
#: src/basic-syntax/methods.md:45
#, fuzzy
msgid ""
"Add a `Rectangle::square(width: u32)` constructor to illustrate that such "
"static methods can take arbitrary parameters."
msgstr ""
"新增一个 `Rectangle::new_square(width: u32)` 构造函数来说明构造函数可以接受任"
"意参数。"
#: src/basic-syntax/functions-interlude.md:1
msgid "Function Overloading"
msgstr "函数重载"
#: src/basic-syntax/functions-interlude.md:3
msgid "Overloading is not supported:"
msgstr "不支持重载:"
#: src/basic-syntax/functions-interlude.md:5
msgid "Each function has a single implementation:"
msgstr "每一个函数都只有一种实现:"
#: src/basic-syntax/functions-interlude.md:6
msgid "Always takes a fixed number of parameters."
msgstr "始终接受固定个数的形参。"
#: src/basic-syntax/functions-interlude.md:7
msgid "Always takes a single set of parameter types."
msgstr "始终接受一组形参类型。"
#: src/basic-syntax/functions-interlude.md:8
msgid "Default values are not supported:"
msgstr "不支持提供默认值:"
#: src/basic-syntax/functions-interlude.md:9
msgid "All call sites have the same number of arguments."
msgstr "实参的数量在所有调用的地方都是一样的。"
#: src/basic-syntax/functions-interlude.md:10
msgid "Macros are sometimes used as an alternative."
msgstr "有时可以用宏(Macro)作为替代。"
#: src/basic-syntax/functions-interlude.md:12
msgid "However, function parameters can be generic:"
msgstr "然而,函数形参可以是泛型(generics):"
#: src/basic-syntax/functions-interlude.md:14
msgid ""
"```rust,editable\n"
"fn pick_one(a: T, b: T) -> T {\n"
" if std::process::id() % 2 == 0 { a } else { b }\n"
"}\n"
"\n"
"fn main() {\n"
" println!(\"coin toss: {}\", pick_one(\"heads\", \"tails\"));\n"
" println!(\"cash prize: {}\", pick_one(500, 1000));\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"fn pick_one(a: T, b: T) -> T {\n"
" if std::process::id() % 2 == 0 { a } else { b }\n"
"}\n"
"\n"
"fn main() {\n"
" println!(\"coin toss: {}\", pick_one(\"heads\", \"tails\"));\n"
" println!(\"cash prize: {}\", pick_one(500, 1000));\n"
"}\n"
"```"
#: src/basic-syntax/functions-interlude.md:27
msgid ""
"When using generics, the standard library's `Into` can provide a kind of "
"limited polymorphism on argument types. We will see more details in a later "
"section."
msgstr ""
"标准库中的 `Into` 通过泛型参数提供了一种具有有限多态性的参数类型。详见之后"
"的章节。"
#: src/exercises/day-1/morning.md:1
msgid "Day 1: Morning Exercises"
msgstr "第一天上午习题"
#: src/exercises/day-1/morning.md:3
msgid "In these exercises, we will explore two parts of Rust:"
msgstr "在这些习题中,我们将探索 Rust 的两个部分:"
#: src/exercises/day-1/morning.md:5
msgid "Implicit conversions between types."
msgstr "类型之间的隐式转换。"
#: src/exercises/day-1/morning.md:7
msgid "Arrays and `for` loops."
msgstr "数组和 `for` 循环。"
#: src/exercises/day-1/morning.md:11
msgid "A few things to consider while solving the exercises:"
msgstr "在解题时要考虑几件事:"
#: src/exercises/day-1/morning.md:13
msgid ""
"Use a local Rust installation, if possible. This way you can get auto-"
"completion in your editor. See the page about [Using Cargo](../../cargo.md) "
"for details on installing Rust."
msgstr ""
"最好使用本地安装的 Rust,以实现在编辑器中自动补全。关于安装 Rust 的细节,请参"
"见 \\[使用 Cargo\\] 页面。"
#: src/exercises/day-1/morning.md:17
msgid "Alternatively, use the Rust Playground."
msgstr "也可以使用 Rust Playground 作为替代。"
#: src/exercises/day-1/morning.md:19
msgid ""
"The code snippets are not editable on purpose: the inline code snippets lose "
"their state if you navigate away from the page."
msgstr ""
"页面内嵌的代码片段是不可编辑的:因为离开页面后内嵌代码片段中的修改会丢失。"
#: src/exercises/day-1/morning.md:22 src/exercises/day-2/morning.md:11
#: src/exercises/day-3/morning.md:9 src/exercises/bare-metal/morning.md:7
#: src/exercises/concurrency/morning.md:12
#, fuzzy
msgid ""
"After looking at the exercises, you can look at the [solutions](solutions-"
"morning.md) provided."
msgstr "读完习题后,可以阅读本书提供的 \\[题解\\]。"
#: src/exercises/day-1/implicit-conversions.md:3
msgid ""
"Rust will not automatically apply _implicit conversions_ between types "
"([unlike C++](https://en.cppreference.com/w/cpp/language/"
"implicit_conversion)). You can see this in a program like this:"
msgstr ""
"[与 C++ 不同](https://en.cppreference.com/w/cpp/language/"
"implicit_conversion),Rust 不会自动进行 _隐式类型转换_。例如,下面的程序中不"
"存在隐式类型转换:"
#: src/exercises/day-1/implicit-conversions.md:20
msgid ""
"The Rust integer types all implement the [`From`](https://doc.rust-lang."
"org/std/convert/trait.From.html) and [`Into`](https://doc.rust-lang.org/"
"std/convert/trait.Into.html) traits to let us convert between them. The "
"`From` trait has a single `from()` method and similarly, the `Into` "
"trait has a single `into()` method. Implementing these traits is how a type "
"expresses that it can be converted into another type."
msgstr ""
"Rust 的整数类型都实现了 [`From`](https://doc.rust-lang.org/std/convert/"
"trait.From.html) 和 [`Into`](https://doc.rust-lang.org/std/convert/trait."
"Into.html) trait,使得我们可以在它们之间进行转换。`From` trait 包含 "
"`from()` 方法,`Into` trait 包含 `into()` 方法。类型通过实现这些 trait 来"
"表达它将被如何转换为另一个类型。"
#: src/exercises/day-1/implicit-conversions.md:26
msgid ""
"The standard library has an implementation of `From for i16`, which "
"means that we can convert a variable `x` of type `i8` to an `i16` by "
"calling `i16::from(x)`. Or, simpler, with `x.into()`, because `From for "
"i16` implementation automatically create an implementation of `Into for "
"i8`."
msgstr ""
"标准库中包含 `From for i16` 的实现,即我们可以通过调用 `i16::from(x)` 来"
"将 `i8` 类型的变量 `x` 转换为 `i16`。或者也可以简单地使用 `x.into()`,因为 "
"`From for i16` 的实现会自动创建 `Into for i8` 的实现。"
#: src/exercises/day-1/implicit-conversions.md:31
msgid ""
"The same applies for your own `From` implementations for your own types, so "
"it is sufficient to only implement `From` to get a respective `Into` "
"implementation automatically."
msgstr ""
"这同样也适用于自定义类型的 `From` 实现,只需实现 `From` 就可以自动得到对应的 "
"`Into` 实现。"
#: src/exercises/day-1/implicit-conversions.md:34
msgid "Execute the above program and look at the compiler error."
msgstr "执行上述程序,并查看对应的编译错误。"
#: src/exercises/day-1/implicit-conversions.md:36
msgid "Update the code above to use `into()` to do the conversion."
msgstr "修改代码,使用 `into()` 进行类型转换。"
#: src/exercises/day-1/implicit-conversions.md:38
msgid ""
"Change the types of `x` and `y` to other things (such as `f32`, `bool`, "
"`i128`) to see which types you can convert to which other types. Try "
"converting small types to big types and the other way around. Check the "
"[standard library documentation](https://doc.rust-lang.org/std/convert/trait."
"From.html) to see if `From` is implemented for the pairs you check."
msgstr ""
"修改 `x` 和 `y` 的类型(例如 `f32`, `bool`, `i128` 等)来了解哪些类型之间可以"
"相互转换。尝试将较小的类型转换为较大的类型和将较大的类型转换为较小的类型。阅"
"读 [标准库文档](https://doc.rust-lang.org/std/convert/trait.From.html) 来了解"
"对于你所尝试的两个类型 `From` 是否已被实现。"
#: src/exercises/day-1/for-loops.md:1
#: src/exercises/day-1/solutions-morning.md:3
msgid "Arrays and `for` Loops"
msgstr "数组与 `for` 循环"
#: src/exercises/day-1/for-loops.md:3
msgid "We saw that an array can be declared like this:"
msgstr "我们可以这样声明一个数组:"
#: src/exercises/day-1/for-loops.md:9
msgid ""
"You can print such an array by asking for its debug representation with `{:?}"
"`:"
msgstr "你可以使用 `{:?}` 来打印这种数组的调试格式:"
#: src/exercises/day-1/for-loops.md:19
msgid ""
"Rust lets you iterate over things like arrays and ranges using the `for` "
"keyword:"
msgstr "在 Rust 中,可以使用 `for` 关键词遍历数组和区间等元素:"
#: src/exercises/day-1/for-loops.md:22
#, fuzzy
msgid ""
"```rust,editable\n"
"fn main() {\n"
" let array = [10, 20, 30];\n"
" print!(\"Iterating over array:\");\n"
" for n in &array {\n"
" print!(\" {n}\");\n"
" }\n"
" println!();\n"
"\n"
" print!(\"Iterating over range:\");\n"
" for i in 0..3 {\n"
" print!(\" {}\", array[i]);\n"
" }\n"
" println!();\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"fn main() {\n"
" let array = [10, 20, 30];\n"
" print!(\"Iterating over array:\");\n"
" for n in array {\n"
" print!(\" {n}\");\n"
" }\n"
" println!();\n"
"\n"
" print!(\"Iterating over range:\");\n"
" for i in 0..3 {\n"
" print!(\" {}\", array[i]);\n"
" }\n"
" println!();\n"
"}\n"
"```"
#: src/exercises/day-1/for-loops.md:39
msgid ""
"Use the above to write a function `pretty_print` which pretty-print a matrix "
"and a function `transpose` which will transpose a matrix (turn rows into "
"columns):"
msgstr ""
"使用以上知识,写一个用易读的格式输出矩阵的 `pretty_print` 函数,以及一个对矩"
"阵进行转置(将行和列互换)的 `transpose` 函数:"
#: src/exercises/day-1/for-loops.md:49
msgid "Hard-code both functions to operate on 3 × 3 matrices."
msgstr "硬编码这两个函数,让它们处理 3 × 3 的矩阵。"
#: src/exercises/day-1/for-loops.md:51
msgid ""
"Copy the code below to and implement the "
"functions:"
msgstr "将下面的代码复制到 并实现上述函数:"
#: src/exercises/day-1/for-loops.md:54
msgid ""
"```rust,should_panic\n"
"// TODO: remove this when you're done with your implementation.\n"
"#![allow(unused_variables, dead_code)]\n"
"\n"
"fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] {\n"
" unimplemented!()\n"
"}\n"
"\n"
"fn pretty_print(matrix: &[[i32; 3]; 3]) {\n"
" unimplemented!()\n"
"}\n"
"\n"
"fn main() {\n"
" let matrix = [\n"
" [101, 102, 103], // <-- the comment makes rustfmt add a newline\n"
" [201, 202, 203],\n"
" [301, 302, 303],\n"
" ];\n"
"\n"
" println!(\"matrix:\");\n"
" pretty_print(&matrix);\n"
"\n"
" let transposed = transpose(matrix);\n"
" println!(\"transposed:\");\n"
" pretty_print(&transposed);\n"
"}\n"
"```"
msgstr ""
"```rust,should_panic\n"
"// TODO: 完成你的实现后移除此行。\n"
"#![allow(unused_variables, dead_code)]\n"
"\n"
"fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] {\n"
" unimplemented!()\n"
"}\n"
"\n"
"fn pretty_print(matrix: &[[i32; 3]; 3]) {\n"
" unimplemented!()\n"
"}\n"
"\n"
"fn main() {\n"
" let matrix = [\n"
" [101, 102, 103], // <-- 这个注释会让 rustfmt 添加一个新行\n"
" [201, 202, 203],\n"
" [301, 302, 303],\n"
" ];\n"
"\n"
" println!(\"matrix:\");\n"
" pretty_print(&matrix);\n"
"\n"
" let transposed = transpose(matrix);\n"
" println!(\"transposed:\");\n"
" pretty_print(&transposed);\n"
"}\n"
"```"
#: src/exercises/day-1/for-loops.md:82
msgid "Bonus Question"
msgstr "附加题"
#: src/exercises/day-1/for-loops.md:84
msgid ""
"Could you use `&[i32]` slices instead of hard-coded 3 × 3 matrices for your "
"argument and return types? Something like `&[&[i32]]` for a two-dimensional "
"slice-of-slices. Why or why not?"
msgstr ""
"是否可以使用 `&[i32]` 切片而不是硬编码的 3 × 3 矩阵作为函数的参数和返回类型?"
"例如使用 `&[&[i32]]` 表示一个二维的切片的切片。为什么这样做是可行或不可行的?"
#: src/exercises/day-1/for-loops.md:89
msgid ""
"See the [`ndarray` crate](https://docs.rs/ndarray/) for a production quality "
"implementation."
msgstr ""
"参考 [`ndarray` crate](https://docs.rs/ndarray/) 以了解该功能满足生产环境质量"
"的实现。"
#: src/exercises/day-1/for-loops.md:94
msgid ""
"The solution and the answer to the bonus section are available in the "
"[Solution](solutions-morning.md#arrays-and-for-loops) section."
msgstr ""
"题目解答和附加题的答案在 [题解](solutions-morning.md#arrays-and-for-loops) 章"
"节中。"
#: src/exercises/day-1/for-loops.md:97
msgid ""
"The use of the reference `&array` within `for n in &array` is a subtle "
"preview of issues of ownership that will come later in the afternoon."
msgstr ""
"在“for n in &array”中使用引用“&array”这一做法巧妙地预先展示了下午将谈到的所有"
"权问题。"
#: src/exercises/day-1/for-loops.md:100
msgid "Without the `&`..."
msgstr "如果不使用“&”…"
#: src/exercises/day-1/for-loops.md:101
msgid ""
"The loop would have been one that consumes the array. This is a change "
"[introduced in the 2021 Edition](https://doc.rust-lang.org/edition-guide/"
"rust-2021/IntoIterator-for-arrays.html)."
msgstr ""
"循环将会是一个使用数组的循环。这是一项[在 2021 年版中引入](https://doc.rust-"
"lang.org/edition-guide/rust-2021/IntoIterator-for-arrays.html)的变更。"
#: src/exercises/day-1/for-loops.md:104
msgid ""
"An implicit array copy would have occurred. Since `i32` is a copy type, "
"then `[i32; 3]` is also a copy type."
msgstr ""
"会发生隐式数组复制。由于“i32”是复制类型,因此“\\[i32; 3\\]”也是复制类型。"
#: src/control-flow.md:3
msgid ""
"As we have seen, `if` is an expression in Rust. It is used to conditionally "
"evaluate one of two blocks, but the blocks can have a value which then "
"becomes the value of the `if` expression. Other control flow expressions "
"work similarly in Rust."
msgstr ""
"正如我们所知,`if` 是 Rust 中的一个表达式。它用于有条件地 评估两个块中的一"
"个,但这些块可以有一个值, 然后成为 `if` 表达式的值。其他控制流表达式在 Rust "
"中也有类似 的运作方式。"
#: src/control-flow/blocks.md:3
#, fuzzy
msgid ""
"A block in Rust contains a sequence of expressions. Each block has a value "
"and a type, which are those of the last expression of the block:"
msgstr "Rust 中的块包含值和类型:值是 块的最后一个表达式:"
#: src/control-flow/blocks.md:27
#, fuzzy
msgid ""
"If the last expression ends with `;`, then the resulting value and type is "
"`()`."
msgstr "不过,如果最后一个表达式以 `;` 结尾,那么生成的值和类型为 `()`。"
#: src/control-flow/blocks.md:29
msgid ""
"The same rule is used for functions: the value of the function body is the "
"return value:"
msgstr "同样的规则也适用于函数:函数主体的值 是返回值:"
#: src/control-flow/blocks.md:45 src/enums.md:34 src/enums/sizes.md:28
#: src/pattern-matching.md:25 src/pattern-matching/match-guards.md:22
#: src/structs.md:31 src/methods.md:30 src/methods/example.md:46
msgid "Key Points:"
msgstr "关键点:"
#: src/control-flow/blocks.md:46
msgid ""
"The point of this slide is to show that blocks have a type and value in "
"Rust. "
msgstr "这张幻灯片的重点是说明在 Rust 中,块有类型和值。"
#: src/control-flow/blocks.md:47
msgid ""
"You can show how the value of the block changes by changing the last line in "
"the block. For instance, adding/removing a semicolon or using a `return`."
msgstr ""
"你可以通过更改块的最后一行,来展示块值的变化情况。例如,添加/移除分号或使用 "
"`return`。"
#: src/control-flow/if-expressions.md:1
msgid "`if` expressions"
msgstr "`if` 表达式"
#: src/control-flow/if-expressions.md:3
msgid ""
"You use [`if` expressions](https://doc.rust-lang.org/reference/expressions/"
"if-expr.html#if-expressions) exactly like `if` statements in other languages:"
msgstr ""
"[`if` 表达式](https://doc.rust-lang.org/reference/expressions/if-expr."
"html#if-expressions) 的用法与其他语言中的 `if` 语句完全一样。"
#: src/control-flow/if-expressions.md:18
msgid ""
"In addition, you can use `if` as an expression. The last expression of each "
"block becomes the value of the `if` expression:"
msgstr ""
"此外,你还可以将 `if` 用作一个表达式。每个块的最后一个表达式 将成为 `if` 表达"
"式的值:"
#: src/control-flow/if-expressions.md:35
msgid ""
"Because `if` is an expression and must have a particular type, both of its "
"branch blocks must have the same type. Consider showing what happens if you "
"add `;` after `x / 2` in the second example."
msgstr ""
"由于 `if` 是一个表达式且必须有一个特定的类型,因此它的两个分支块必须有相同的"
"类型。考虑在第二个示例中将 `;` 添加到 `x / 2` 的后面,看看会出现什么情况。"
#: src/control-flow/for-expressions.md:1
msgid "`for` loops"
msgstr "`for` 循环"
#: src/control-flow/for-expressions.md:3
#, fuzzy
msgid ""
"The [`for` loop](https://doc.rust-lang.org/std/keyword.for.html) is closely "
"related to the [`while let` loop](while-let-expressions.md). It will "
"automatically call `into_iter()` on the expression and then iterate over it:"
msgstr ""
"[`for` 循环](https://doc.rust-lang.org/std/keyword.for.html) 与 [`when let` "
"循环](when-let-expression.md)密切相关。它会 自动对表达式调用 `into_iter()`,"
"然后对其进行迭代:"
#: src/control-flow/for-expressions.md:22
msgid "You can use `break` and `continue` here as usual."
msgstr "你可以在此照常使用 `break` 和 `continue`。"
#: src/control-flow/for-expressions.md:26
msgid "Index iteration is not a special syntax in Rust for just that case."
msgstr "在这种情况下,索引迭代在 Rust 中并不是一个特殊的语法。"
#: src/control-flow/for-expressions.md:27
msgid "`(0..10)` is a range that implements an `Iterator` trait. "
msgstr "`(0..10)` 是实现 `Iterator` trait 的区间。"
#: src/control-flow/for-expressions.md:28
msgid ""
"`step_by` is a method that returns another `Iterator` that skips every other "
"element. "
msgstr "`step_by` 是返回另一个 `Iterator` 的方法,用于逐一跳过所有其他元素。"
#: src/control-flow/for-expressions.md:29
msgid ""
"Modify the elements in the vector and explain the compiler errors. Change "
"vector `v` to be mutable and the for loop to `for x in v.iter_mut()`."
msgstr ""
"修改矢量中的元素并说明编译器错误。将矢量 `v` 改为可变,并将 for 循环改为 "
"`for x in v.iter_mut()`。"
#: src/control-flow/while-expressions.md:1
msgid "`while` loops"
msgstr "`while` 循环"
#: src/control-flow/while-expressions.md:3
msgid ""
"The [`while` keyword](https://doc.rust-lang.org/reference/expressions/loop-"
"expr.html#predicate-loops) works very similar to other languages:"
msgstr ""
"[`while` 关键字](https://doc.rust-lang.org/reference/expressions/loop-expr."
"html#predicate-loops) 的工作方式与其他语言非常相似:"
#: src/control-flow/break-continue.md:1
msgid "`break` and `continue`"
msgstr "`break` 和 `continue`"
#: src/control-flow/break-continue.md:3
msgid ""
"If you want to exit a loop early, use [`break`](https://doc.rust-lang.org/"
"reference/expressions/loop-expr.html#break-expressions),"
msgstr ""
"如果你想提前退出循环,请使用 [`break`](https://doc.rust-lang.org/reference/"
"expressions/loop-expr.html#break-expressions),"
#: src/control-flow/break-continue.md:4
msgid ""
"If you want to immediately start the next iteration use [`continue`](https://"
"doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions)."
msgstr ""
"如果需要立即启动 下一次迭代,请使用 [`continue`](https://doc.rust-lang.org/"
"reference/expressions/loop-expr.html#continue-expressions)。"
#: src/control-flow/break-continue.md:7
msgid ""
"Both `continue` and `break` can optionally take a label argument which is "
"used to break out of nested loops:"
msgstr "`continue` 和 `break` 都可以选择接受一个标签参数,用来 终止嵌套循环:"
#: src/control-flow/break-continue.md:29
msgid ""
"In this case we break the outer loop after 3 iterations of the inner loop."
msgstr "在本示例中,我们会在内循环 3 次迭代后终止外循环。"
#: src/control-flow/loop-expressions.md:1
msgid "`loop` expressions"
msgstr "`loop` 表达式"
#: src/control-flow/loop-expressions.md:3
msgid ""
"Finally, there is a [`loop` keyword](https://doc.rust-lang.org/reference/"
"expressions/loop-expr.html#infinite-loops) which creates an endless loop."
msgstr ""
"最后是用于创建无限循环的 [`loop` 关键字](https://doc.rust-lang.org/reference/"
"expressions/loop-expr.html#infinite-loops) 。"
#: src/control-flow/loop-expressions.md:6
msgid "Here you must either `break` or `return` to stop the loop:"
msgstr "在下例中,你必须 `break` 或 `return` 才能停止循环:"
#: src/control-flow/loop-expressions.md:28
msgid "Break the `loop` with a value (e.g. `break 8`) and print it out."
msgstr "用一个值(例如 `break 8`)来中断 `loop` 并将其输出。"
#: src/control-flow/loop-expressions.md:29
msgid ""
"Note that `loop` is the only looping construct which returns a non-trivial "
"value. This is because it's guaranteed to be entered at least once (unlike "
"`while` and `for` loops)."
msgstr ""
"请注意,`loop` 是唯一返回有意义的值的循环结构。 这是因为它保证至少被输入一次"
"(与 `while` 和 `for` 循环不同)。"
#: src/basic-syntax/variables.md:3
msgid ""
"Rust provides type safety via static typing. Variable bindings are immutable "
"by default:"
msgstr "Rust 通过静态类型实现了类型安全。变量绑定默认是不可变的:"
#: src/basic-syntax/variables.md:18
msgid ""
"Due to type inference the `i32` is optional. We will gradually show the "
"types less and less as the course progresses."
msgstr ""
"由于类型推导,`i32` 可以省略。随着课程推进,我们会越来越少地看到类型声明。"
#: src/basic-syntax/type-inference.md:3
msgid "Rust will look at how the variable is _used_ to determine the type:"
msgstr "Rust 会根据变量的使用来确定其类型:"
#: src/basic-syntax/type-inference.md:27
msgid ""
"This slide demonstrates how the Rust compiler infers types based on "
"constraints given by variable declarations and usages."
msgstr "这张幻灯片演示了 Rust 编译器是如何根据变量声明和用法来推导其类型的。"
#: src/basic-syntax/type-inference.md:29
msgid ""
"It is very important to emphasize that variables declared like this are not "
"of some sort of dynamic \"any type\" that can hold any data. The machine "
"code generated by such declaration is identical to the explicit declaration "
"of a type. The compiler does the job for us and helps us write more concise "
"code."
msgstr ""
"需要重点强调的是这样声明的变量并非像那种动态类型语言中可以持有任何数据的“任何"
"类型”。这种声明所生成的机器码与明确类型声明完全相同。编译器进行类型推导能够让"
"我们编写更简略的代码。"
#: src/basic-syntax/type-inference.md:33
#, fuzzy
msgid ""
"The following code tells the compiler to copy into a certain generic "
"container without the code ever explicitly specifying the contained type, "
"using `_` as a placeholder:"
msgstr ""
"下面的代码通过使用 `_` 占位符来告诉编译器无需明确指定其类型就可以将对应数据拷"
"贝到该容器: "
#: src/basic-syntax/type-inference.md:48
#, fuzzy
msgid ""
"[`collect`](https://doc.rust-lang.org/stable/std/iter/trait.Iterator."
"html#method.collect) relies on [`FromIterator`](https://doc.rust-lang.org/"
"std/iter/trait.FromIterator.html), which [`HashSet`](https://doc.rust-lang."
"org/std/collections/struct.HashSet.html#impl-FromIterator%3CT%3E-for-"
"HashSet%3CT,+S%3E) implements."
msgstr ""
"[`collect`](https://doc.rust-lang.org/stable/std/iter/trait.Iterator."
"html#method.collect) 依赖 [`HashSet`](https://doc.rust-lang.org/std/iter/"
"trait.FromIterator.html) 实现的 `FromIterator`。"
#: src/basic-syntax/static-and-const.md:1
msgid "Static and Constant Variables"
msgstr "静态变量和常量"
#: src/basic-syntax/static-and-const.md:3
msgid ""
"Static and constant variables are two different ways to create globally-"
"scoped values that cannot be moved or reallocated during the execution of "
"the program. "
msgstr ""
"静态变量和常量是创建全局范围值的两种不同方法,这类值在程序执行期间无法移动或"
"重新分配。"
#: src/basic-syntax/static-and-const.md:6
msgid "`const`"
msgstr "`const`"
#: src/basic-syntax/static-and-const.md:8
msgid ""
"Constant variables are evaluated at compile time and their values are "
"inlined wherever they are used:"
msgstr "系统会在编译时对常量变量进行求值;无论在何处使用,其值都会被内嵌:"
#: src/basic-syntax/static-and-const.md:30
msgid ""
"According to the [Rust RFC Book](https://rust-lang.github.io/rfcs/0246-const-"
"vs-static.html) these are inlined upon use."
msgstr ""
"根据 [Rust RFC Book](https://rust-lang.github.io/rfcs/0246-const-vs-static."
"html) 这些变量在使用时是内联 (inlined) 的。"
#: src/basic-syntax/static-and-const.md:32
msgid ""
"Only functions marked `const` can be called at compile time to generate "
"`const` values. `const` functions can however be called at runtime."
msgstr ""
"在编译时只能调用标记为“const”的函数以生成“const”值。不过,可在运行时调"
"用“const”函数。"
#: src/basic-syntax/static-and-const.md:34
msgid "`static`"
msgstr "`static`"
#: src/basic-syntax/static-and-const.md:36
msgid ""
"Static variables will live during the whole execution of the program, and "
"therefore will not move:"
msgstr "静态变量在程序的整个执行过程中始终有效,因此不会移动:"
#: src/basic-syntax/static-and-const.md:38
msgid ""
"```rust,editable\n"
"static BANNER: &str = \"Welcome to RustOS 3.14\";\n"
"\n"
"fn main() {\n"
" println!(\"{BANNER}\");\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"static BANNER: &str = \"Welcome to RustOS 3.14\";\n"
"\n"
"fn main() {\n"
" println!(\"{BANNER}\");\n"
"}\n"
"```"
#: src/basic-syntax/static-and-const.md:46
#, fuzzy
msgid ""
"As noted in the [Rust RFC Book](https://rust-lang.github.io/rfcs/0246-const-"
"vs-static.html), these are not inlined upon use and have an actual "
"associated memory location. This is useful for unsafe and embedded code, "
"and the variable lives through the entirety of the program execution. When a "
"globally-scoped value does not have a reason to need object identity, "
"`const` is generally preferred."
msgstr ""
"正如 [Rust RFC Book](https://rust-lang.github.io/rfcs/0246-const-vs-static."
"html) 中所述,这些变量在使用时并不是内联的,而且还具有实际相关联的内存位置。"
"这对于不安全的嵌入式代码是有用的,并且这些变量存在于整个程序的执行过程之中。"
#: src/basic-syntax/static-and-const.md:50
msgid ""
"Because `static` variables are accessible from any thread, they must be "
"`Sync`. Interior mutability is possible through a [`Mutex`](https://doc.rust-"
"lang.org/std/sync/struct.Mutex.html), atomic or similar. It is also possible "
"to have mutable statics, but they require manual synchronisation so any "
"access to them requires `unsafe` code. We will look at [mutable statics](../"
"unsafe/mutable-static-variables.md) in the chapter on Unsafe Rust."
msgstr ""
"由于“static”变量可从任何线程访问,因此它们必须是“Sync”。内部可变性可通过[“互"
"斥量”](https://doc.rust-lang.org/std/sync/struct.Mutex.html)、原子性或类似对"
"象实现。也可能具有可变静态项,但它们需要手动同步,因此对它们的任何访问都需"
"要“unsafe”代码。我们将在“不安全 Rust”章节中探讨[可变静态项](../unsafe/"
"mutable-static-variables.md)。"
#: src/basic-syntax/static-and-const.md:58
msgid "Mention that `const` behaves semantically similar to C++'s `constexpr`."
msgstr "值得一提的是,`const` 在语义上与C++的 `constexpr` 类似。"
#: src/basic-syntax/static-and-const.md:59
msgid ""
"`static`, on the other hand, is much more similar to a `const` or mutable "
"global variable in C++."
msgstr "另一方面,`static` 远远更类似于C++中的 `const` 或可改变的全局变量。"
#: src/basic-syntax/static-and-const.md:60
#, fuzzy
msgid ""
"`static` provides object identity: an address in memory and state as "
"required by types with interior mutability such as `Mutex`."
msgstr ""
"“static”提供对象标识:内存中的一个地址及具有内部可变性的类型(如“Mutex\n"
"\n"
"”)所需的状态。"
#: src/basic-syntax/static-and-const.md:61
msgid ""
"It isn't super common that one would need a runtime evaluated constant, but "
"it is helpful and safer than using a static."
msgstr ""
"虽然需要使用在运行中求值的常量的情况并不是很常见,但是它是有帮助的,而且比使"
"用静态变量更安全。"
#: src/basic-syntax/static-and-const.md:62
msgid "`thread_local` data can be created with the macro `std::thread_local`."
msgstr "可以使用宏“std::thread_local”创建“thread_local”数据。"
#: src/basic-syntax/static-and-const.md:64
msgid "Properties table:"
msgstr "属性表:"
#: src/basic-syntax/static-and-const.md:66
msgid "Property"
msgstr "属性"
#: src/basic-syntax/static-and-const.md:66
#, fuzzy
msgid "Static"
msgstr "`static`"
#: src/basic-syntax/static-and-const.md:66
msgid "Constant"
msgstr "常量"
#: src/basic-syntax/static-and-const.md:68
msgid "Has an address in memory"
msgstr "在内存中有地址"
#: src/basic-syntax/static-and-const.md:68
#: src/basic-syntax/static-and-const.md:69
#: src/basic-syntax/static-and-const.md:71
#: src/basic-syntax/static-and-const.md:72
msgid "Yes"
msgstr "是"
#: src/basic-syntax/static-and-const.md:68
msgid "No (inlined)"
msgstr "否(内嵌)"
#: src/basic-syntax/static-and-const.md:69
#, fuzzy
msgid "Lives for the entire duration of the program"
msgstr "`main` 函数是程序的入口。"
#: src/basic-syntax/static-and-const.md:69
#: src/basic-syntax/static-and-const.md:70
#: src/basic-syntax/static-and-const.md:72
msgid "No"
msgstr "否"
#: src/basic-syntax/static-and-const.md:70
msgid "Can be mutable"
msgstr "可变"
#: src/basic-syntax/static-and-const.md:70
msgid "Yes (unsafe)"
msgstr "是(不安全)"
#: src/basic-syntax/static-and-const.md:71
#, fuzzy
msgid "Evaluated at compile time"
msgstr "值在编译时具有已知的固定大小。"
#: src/basic-syntax/static-and-const.md:71
msgid "Yes (initialised at compile time)"
msgstr "是(在编译时被初始化)"
#: src/basic-syntax/static-and-const.md:72
msgid "Inlined wherever it is used"
msgstr "内嵌在使用它的任何位置"
#: src/basic-syntax/scopes-shadowing.md:3
msgid ""
"You can shadow variables, both those from outer scopes and variables from "
"the same scope:"
msgstr "你可以隐藏变量,位于外部作用域的变量和 相同作用域的变量都可以:"
#: src/basic-syntax/scopes-shadowing.md:6
msgid ""
"```rust,editable\n"
"fn main() {\n"
" let a = 10;\n"
" println!(\"before: {a}\");\n"
"\n"
" {\n"
" let a = \"hello\";\n"
" println!(\"inner scope: {a}\");\n"
"\n"
" let a = true;\n"
" println!(\"shadowed in inner scope: {a}\");\n"
" }\n"
"\n"
" println!(\"after: {a}\");\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"fn main() {\n"
" let a = 10;\n"
" println!(\"before: {a}\");\n"
"\n"
" {\n"
" let a = \"hello\";\n"
" println!(\"inner scope: {a}\");\n"
"\n"
" let a = true;\n"
" println!(\"shadowed in inner scope: {a}\");\n"
" }\n"
"\n"
" println!(\"after: {a}\");\n"
"}\n"
"```"
#: src/basic-syntax/scopes-shadowing.md:25
msgid ""
"Definition: Shadowing is different from mutation, because after shadowing "
"both variable's memory locations exist at the same time. Both are available "
"under the same name, depending where you use it in the code. "
msgstr ""
"定义: 遮蔽和变更(mutation)不同,因为在遮蔽之后,两个变量都会同时存在于内存"
"的不同位置中。在同一个名字下的两个变量都是可以被使用的,但是你在代码的哪里使"
"用会最终决定你使用哪一个变量。"
#: src/basic-syntax/scopes-shadowing.md:26
msgid "A shadowing variable can have a different type. "
msgstr "一个遮蔽变量可以具有不同的类型。"
#: src/basic-syntax/scopes-shadowing.md:27
msgid ""
"Shadowing looks obscure at first, but is convenient for holding on to values "
"after `.unwrap()`."
msgstr "隐藏起初看起来会有些晦涩,但是它很便于存 `.unwrap()` 之后的得到的值。"
#: src/basic-syntax/scopes-shadowing.md:28
msgid ""
"The following code demonstrates why the compiler can't simply reuse memory "
"locations when shadowing an immutable variable in a scope, even if the type "
"does not change."
msgstr ""
"以下代码说明了为什么在作用域内隐藏一个不可变的变量时,即使是在变量类型没有改"
"变的情况下,编译器也不能简单地重复利用之前的内存位置。"
#: src/enums.md:3
msgid ""
"The `enum` keyword allows the creation of a type which has a few different "
"variants:"
msgstr "`enum` 关键字允许创建具有几个 不同变体的类型:"
#: src/enums.md:6
msgid ""
"```rust,editable\n"
"fn generate_random_number() -> i32 {\n"
" // Implementation based on https://xkcd.com/221/\n"
" 4 // Chosen by fair dice roll. Guaranteed to be random.\n"
"}\n"
"\n"
"#[derive(Debug)]\n"
"enum CoinFlip {\n"
" Heads,\n"
" Tails,\n"
"}\n"
"\n"
"fn flip_coin() -> CoinFlip {\n"
" let random_number = generate_random_number();\n"
" if random_number % 2 == 0 {\n"
" return CoinFlip::Heads;\n"
" } else {\n"
" return CoinFlip::Tails;\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
" println!(\"You got: {:?}\", flip_coin());\n"
"}\n"
"```"
msgstr ""
#: src/enums.md:36
msgid "Enumerations allow you to collect a set of values under one type"
msgstr "枚举允许你从一种类型下收集一组值"
#: src/enums.md:37
#, fuzzy
msgid ""
"This page offers an enum type `CoinFlip` with two variants `Heads` and "
"`Tails`. You might note the namespace when using variants."
msgstr ""
"本页提供了一个枚举类型 `CoinFlip`,其中包含 `Heads` 和`Tail`两个变体。在使用"
"变体时,你可能会注意到命名空间。"
#: src/enums.md:38
msgid "This might be a good time to compare Structs and Enums:"
msgstr "这可能是比较结构体和枚举的好时机:"
#: src/enums.md:39
msgid ""
"In both, you can have a simple version without fields (unit struct) or one "
"with different types of fields (variant payloads). "
msgstr ""
"在这两者中,你可以获得一个不含字段的简单版本(单位结构体),或一个包含不同类"
"型字段的版本(变体载荷)。"
#: src/enums.md:40
msgid "In both, associated functions are defined within an `impl` block."
msgstr "在这两者中,关联的函数都在 `impl` 块中定义。"
#: src/enums.md:41
msgid ""
"You could even implement the different variants of an enum with separate "
"structs but then they wouldn’t be the same type as they would if they were "
"all defined in an enum. "
msgstr ""
"你甚至可以使用单独的结构体实现枚举的不同变体,但这样一来,如果它们都已在枚举"
"中定义,类型与之前也不一样。"
#: src/enums/variant-payloads.md:3
msgid ""
"You can define richer enums where the variants carry data. You can then use "
"the `match` statement to extract the data from each variant:"
msgstr ""
"你可以定义更丰富的枚举,其中变体会携带数据。然后,你可以使用 `match` 语句从每"
"个变体中提取数据:"
#: src/enums/variant-payloads.md:6
msgid ""
"```rust,editable\n"
"enum WebEvent {\n"
" PageLoad, // Variant without payload\n"
" KeyPress(char), // Tuple struct variant\n"
" Click { x: i64, y: i64 }, // Full struct variant\n"
"}\n"
"\n"
"#[rustfmt::skip]\n"
"fn inspect(event: WebEvent) {\n"
" match event {\n"
" WebEvent::PageLoad => println!(\"page loaded\"),\n"
" WebEvent::KeyPress(c) => println!(\"pressed '{c}'\"),\n"
" WebEvent::Click { x, y } => println!(\"clicked at x={x}, y={y}\"),\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
" let load = WebEvent::PageLoad;\n"
" let press = WebEvent::KeyPress('x');\n"
" let click = WebEvent::Click { x: 20, y: 80 };\n"
"\n"
" inspect(load);\n"
" inspect(press);\n"
" inspect(click);\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"enum WebEvent {\n"
" PageLoad, // Variant without payload\n"
" KeyPress(char), // Tuple struct variant\n"
" Click { x: i64, y: i64 }, // Full struct variant\n"
"}\n"
"\n"
"#[rustfmt::skip]\n"
"fn inspect(event: WebEvent) {\n"
" match event {\n"
" WebEvent::PageLoad => println!(\"page loaded\"),\n"
" WebEvent::KeyPress(c) => println!(\"pressed '{c}'\"),\n"
" WebEvent::Click { x, y } => println!(\"clicked at x={x}, y={y}\"),\n"
" }\n"
"}\n"
"\n"
"fn main() {\n"
" let load = WebEvent::PageLoad;\n"
" let press = WebEvent::KeyPress('x');\n"
" let click = WebEvent::Click { x: 20, y: 80 };\n"
"\n"
" inspect(load);\n"
" inspect(press);\n"
" inspect(click);\n"
"}\n"
"```"
#: src/enums/variant-payloads.md:35
msgid ""
"The values in the enum variants can only be accessed after being pattern "
"matched. The pattern binds references to the fields in the \"match arm\" "
"after the `=>`."
msgstr ""
"枚举变体中的值只有在被模式匹配后,才可访问。模式将引用绑定到 `=>` 之后"
"的“match 分支”中的字段。"
#: src/enums/variant-payloads.md:36
msgid ""
"The expression is matched against the patterns from top to bottom. There is "
"no fall-through like in C or C++."
msgstr "表达式会从上到下与模式匹配。没有像 C 或 C++ 中那样的跳转。"
#: src/enums/variant-payloads.md:37
msgid ""
"The match expression has a value. The value is the last expression in the "
"match arm which was executed."
msgstr "匹配表达式拥有一个值。值是 match 分支中被执行的最后一个表达式。"
#: src/enums/variant-payloads.md:38
msgid ""
"Starting from the top we look for what pattern matches the value then run "
"the code following the arrow. Once we find a match, we stop. "
msgstr ""
"从顶部开始,查找与该值匹配的模式,然后沿箭头运行代码。一旦找到匹配,我们便会"
"停止。"
#: src/enums/variant-payloads.md:39
msgid ""
"Demonstrate what happens when the search is inexhaustive. Note the advantage "
"the Rust compiler provides by confirming when all cases are handled. "
msgstr ""
"展示搜索不详尽时会发生的情况。请注意 Rust 编译器的优势,即确认所有情况何时都"
"得到了处理。"
#: src/enums/variant-payloads.md:40
msgid "`match` inspects a hidden discriminant field in the `enum`."
msgstr "`match` 会检查 `enum` 中的隐藏的判别字段。"
#: src/enums/variant-payloads.md:41
msgid ""
"It is possible to retrieve the discriminant by calling `std::mem::"
"discriminant()`"
msgstr "可以通过调用 `std::mem::discriminant()` 来检索判别"
#: src/enums/variant-payloads.md:42
msgid ""
"This is useful, for example, if implementing `PartialEq` for structs where "
"comparing field values doesn't affect equality."
msgstr "这很有用,例如如果为结构体实现 `PartialEq`,比较字段值不会影响等式。"
#: src/enums/variant-payloads.md:43
msgid ""
"`WebEvent::Click { ... }` is not exactly the same as `WebEvent::"
"Click(Click)` with a top level `struct Click { ... }`. The inlined version "
"cannot implement traits, for example."
msgstr ""
"`WebEvent::Click { ... }` 与含顶层 `struct Click { ... }` 的 `WebEvent::"
"Click(Click)` 不完全相同。例如,内嵌版本无法实现 trait。"
#: src/enums/sizes.md:3
msgid ""
"Rust enums are packed tightly, taking constraints due to alignment into "
"account:"
msgstr "Rust 枚举被紧密地打包,考虑到了对齐的影响,因此存在一些限制:"
#: src/enums/sizes.md:5
#, fuzzy
msgid ""
"```rust,editable\n"
"use std::any::type_name;\n"
"use std::mem::{align_of, size_of};\n"
"\n"
"fn dbg_size() {\n"
" println!(\"{}: size {} bytes, align: {} bytes\",\n"
" type_name::(), size_of::(), align_of::());\n"
"}\n"
"\n"
"enum Foo {\n"
" A,\n"
" B,\n"
"}\n"
"\n"
"fn main() {\n"
" dbg_size::();\n"
"}\n"
"```"
msgstr ""
"```rust,editable\n"
"use std::mem::{align_of, size_of};\n"
"\n"
"macro_rules! dbg_size {\n"
" ($t:ty) => {\n"
" println!(\"{}: size {} bytes, align: {} bytes\",\n"
" stringify!($t), size_of::<$t>(), align_of::<$t>());\n"
" };\n"
"}\n"
"\n"
"enum Foo {\n"
" A,\n"
" B,\n"
"}\n"
"\n"
"fn main() {\n"
" dbg_size!(Foo);\n"
"}\n"
"```"
#: src/enums/sizes.md:24
msgid ""
"See the [Rust Reference](https://doc.rust-lang.org/reference/type-layout."
"html)."
msgstr ""
"请参阅 [Rust 引用](https://doc.rust-lang.org/reference/type-layout.html)。"
#: src/enums/sizes.md:30
#, fuzzy
msgid ""
"Internally Rust is using a field (discriminant) to keep track of the enum "
"variant."
msgstr "在内部,Rust 使用字段(判别)来跟踪枚举变体。"
#: src/enums/sizes.md:32
#, fuzzy
msgid ""
"You can control the discriminant if needed (e.g., for compatibility with C):"
msgstr "你可以根据需要控制判别(例如,与 C 的兼容性):"
#: src/enums/sizes.md:50
#, fuzzy
msgid ""
"Without `repr`, the discriminant type takes 2 bytes, because 10001 fits 2 "
"bytes."
msgstr ""
"如果不使用 `repr`,判别类型会占用 2 个字节,因为 10001 是一个 2 个字节的数"
"值。"
#: src/enums/sizes.md:54
#, fuzzy
msgid "Try out other types such as"
msgstr "试试其他类型,例如:"
#: src/enums/sizes.md:56
#, fuzzy
msgid "`dbg_size!(bool)`: size 1 bytes, align: 1 bytes,"
msgstr "`dbg_size!(bool)`:大小占用 1 个字节,对齐占用 1 个字节;"
#: src/enums/sizes.md:57
#, fuzzy
msgid ""
"`dbg_size!(Option)`: size 1 bytes, align: 1 bytes (niche optimization, "
"see below),"
msgstr ""
"`dbg_size!(Option)`:大小占用 1 个字节,对齐占用 1 个字节(小众优化,请"
"参阅下文);"
#: src/enums/sizes.md:58
#, fuzzy
msgid "`dbg_size!(&i32)`: size 8 bytes, align: 8 bytes (on a 64-bit machine),"
msgstr ""
"`dbg_size!(&i32)`:大小占用 8 个字节,对齐占用 8 个字节(在 64 位设备上);"
#: src/enums/sizes.md:59
#, fuzzy
msgid ""
"`dbg_size!(Option<&i32>)`: size 8 bytes, align: 8 bytes (null pointer "
"optimization, see below)."
msgstr ""
"`dbg_size!(Option<&i32>)`:大小占用 8 个字节,对齐占用 8 个字节(Null 指针优"
"化,请参阅下文)。"
#: src/enums/sizes.md:61
#, fuzzy
msgid ""
"Niche optimization: Rust will merge unused bit patterns for the enum "
"discriminant."
msgstr "小众优化:Rust 将对枚举判别合并使用 未使用的位模式。"
#: src/enums/sizes.md:64
#, fuzzy
msgid ""
"Null pointer optimization: For [some types](https://doc.rust-lang.org/std/"
"option/#representation), Rust guarantees that `size_of::()` equals "
"`size_of::