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 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 + // 实际绘制按钮的代码 } } 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)); } 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 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) }