From bcd3ac44f626d62a4cf82a6d057c749cebf8f741 Mon Sep 17 00:00:00 2001 From: qwer252 Date: Wed, 11 Jun 2025 14:57:26 +0800 Subject: [PATCH 1/5] Update lib.rs --- listings/ch18-oop/listing-18-07/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch18-oop/listing-18-07/src/lib.rs b/listings/ch18-oop/listing-18-07/src/lib.rs index b16cd01..4add40e 100644 --- a/listings/ch18-oop/listing-18-07/src/lib.rs +++ b/listings/ch18-oop/listing-18-07/src/lib.rs @@ -23,7 +23,7 @@ pub struct Button { impl Draw for Button { fn draw(&self) { - // code to actually draw a button + // 实际绘制按钮的代码 } } // ANCHOR_END: here From 700d36083bfe6953f13876ab7be93318f886e1ae Mon Sep 17 00:00:00 2001 From: qwer252 Date: Wed, 11 Jun 2025 15:00:59 +0800 Subject: [PATCH 2/5] Update lib.rs --- listings/ch18-oop/listing-18-08/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch18-oop/listing-18-08/src/lib.rs b/listings/ch18-oop/listing-18-08/src/lib.rs index 960fee2..8aeaf5d 100644 --- a/listings/ch18-oop/listing-18-08/src/lib.rs +++ b/listings/ch18-oop/listing-18-08/src/lib.rs @@ -22,6 +22,6 @@ pub struct Button { impl Draw for Button { fn draw(&self) { - // code to actually draw a button + // 实际绘制按钮的代码 } } From c2ef2eb19abae116d1af81874d4014aeb62d30df Mon Sep 17 00:00:00 2001 From: qwer252 Date: Wed, 11 Jun 2025 17:43:14 +0800 Subject: [PATCH 3/5] Update main.rs --- listings/ch20-advanced-features/listing-20-11/src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/listings/ch20-advanced-features/listing-20-11/src/main.rs b/listings/ch20-advanced-features/listing-20-11/src/main.rs index 4e292b1..5938f2f 100644 --- a/listings/ch20-advanced-features/listing-20-11/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-11/src/main.rs @@ -1,8 +1,7 @@ static mut COUNTER: u32 = 0; -/// SAFETY: Calling this from more than a single thread at a time is undefined -/// behavior, so you *must* guarantee you only call it from a single thread at -/// a time. +/// SAFETY: 同时在多个线程调用这个方法是未定义的行为,所以你*必须*保证同一时间只 +/// 有一个线程在调用它。 unsafe fn add_to_count(inc: u32) { unsafe { COUNTER += inc; @@ -11,7 +10,7 @@ unsafe fn add_to_count(inc: u32) { fn main() { unsafe { - // SAFETY: This is only called from a single thread in `main`. + // SAFETY: 它只在 `main` 这一个线程被调用。 add_to_count(3); println!("COUNTER: {}", *(&raw const COUNTER)); } From f9c9174fc6af4947f4c76068847983a19372c3e2 Mon Sep 17 00:00:00 2001 From: qwer252 Date: Wed, 11 Jun 2025 17:46:29 +0800 Subject: [PATCH 4/5] Update main.rs --- listings/ch20-advanced-features/listing-20-12/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/listings/ch20-advanced-features/listing-20-12/src/main.rs b/listings/ch20-advanced-features/listing-20-12/src/main.rs index 2301b0c..3c7abbe 100644 --- a/listings/ch20-advanced-features/listing-20-12/src/main.rs +++ b/listings/ch20-advanced-features/listing-20-12/src/main.rs @@ -1,10 +1,10 @@ // ANCHOR: here unsafe trait Foo { - // methods go here + // 方法在这里 } unsafe impl Foo for i32 { - // method implementations go here + // 方法实现在这里 } // ANCHOR_END: here From e65bdb9c2d07eac38f00eb1233b239d858894800 Mon Sep 17 00:00:00 2001 From: qwer252 Date: Wed, 11 Jun 2025 21:45:00 +0800 Subject: [PATCH 5/5] Update lib.rs --- .../listing-20-40/hello_macro/hello_macro_derive/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/listings/ch20-advanced-features/listing-20-40/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch20-advanced-features/listing-20-40/hello_macro/hello_macro_derive/src/lib.rs index 7ae9e55..8f46a38 100644 --- a/listings/ch20-advanced-features/listing-20-40/hello_macro/hello_macro_derive/src/lib.rs +++ b/listings/ch20-advanced-features/listing-20-40/hello_macro/hello_macro_derive/src/lib.rs @@ -3,10 +3,9 @@ use quote::quote; #[proc_macro_derive(HelloMacro)] pub fn hello_macro_derive(input: TokenStream) -> TokenStream { - // Construct a representation of Rust code as a syntax tree - // that we can manipulate. + // 将 Rust 代码构建成我们可以操作的语法树。 let ast = syn::parse(input).unwrap(); - // Build the trait implementation. + // 生成 trait 的实现。 impl_hello_macro(&ast) }