Merge pull request #890 from qwer252/main

pull/892/head
KaiserY 1 week ago committed by GitHub
commit 294fbbbced
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -23,7 +23,7 @@ pub struct Button {
impl Draw for Button { impl Draw for Button {
fn draw(&self) { fn draw(&self) {
// code to actually draw a button // 实际绘制按钮的代码
} }
} }
// ANCHOR_END: here // ANCHOR_END: here

@ -22,6 +22,6 @@ pub struct Button {
impl Draw for Button { impl Draw for Button {
fn draw(&self) { fn draw(&self) {
// code to actually draw a button // 实际绘制按钮的代码
} }
} }

@ -1,8 +1,7 @@
static mut COUNTER: u32 = 0; static mut COUNTER: u32 = 0;
/// SAFETY: Calling this from more than a single thread at a time is undefined /// SAFETY: 同时在多个线程调用这个方法是未定义的行为,所以你*必须*保证同一时间只
/// behavior, so you *must* guarantee you only call it from a single thread at /// 有一个线程在调用它。
/// a time.
unsafe fn add_to_count(inc: u32) { unsafe fn add_to_count(inc: u32) {
unsafe { unsafe {
COUNTER += inc; COUNTER += inc;
@ -11,7 +10,7 @@ unsafe fn add_to_count(inc: u32) {
fn main() { fn main() {
unsafe { unsafe {
// SAFETY: This is only called from a single thread in `main`. // SAFETY: 它只在 `main` 这一个线程被调用。
add_to_count(3); add_to_count(3);
println!("COUNTER: {}", *(&raw const COUNTER)); println!("COUNTER: {}", *(&raw const COUNTER));
} }

@ -1,10 +1,10 @@
// ANCHOR: here // ANCHOR: here
unsafe trait Foo { unsafe trait Foo {
// methods go here // 方法在这里
} }
unsafe impl Foo for i32 { unsafe impl Foo for i32 {
// method implementations go here // 方法实现在这里
} }
// ANCHOR_END: here // ANCHOR_END: here

@ -3,10 +3,9 @@ use quote::quote;
#[proc_macro_derive(HelloMacro)] #[proc_macro_derive(HelloMacro)]
pub fn hello_macro_derive(input: TokenStream) -> TokenStream { pub fn hello_macro_derive(input: TokenStream) -> TokenStream {
// Construct a representation of Rust code as a syntax tree // 将 Rust 代码构建成我们可以操作的语法树。
// that we can manipulate.
let ast = syn::parse(input).unwrap(); let ast = syn::parse(input).unwrap();
// Build the trait implementation. // 生成 trait 的实现。
impl_hello_macro(&ast) impl_hello_macro(&ast)
} }

Loading…
Cancel
Save