From 0253dc7a4c2571f36ef1a8771650efb94d0cc41a Mon Sep 17 00:00:00 2001 From: YangFong <70502828+YangFong@users.noreply.github.com> Date: Mon, 7 Mar 2022 19:00:10 +0800 Subject: [PATCH] docs: adjust sample code comments --- .../ch04-understanding-ownership/listing-04-03/src/main.rs | 2 +- .../ch04-understanding-ownership/listing-04-04/src/main.rs | 4 ++-- .../no-listing-08-reference-with-annotations/src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs index 21bd806..d42e3c1 100644 --- a/listings/ch04-understanding-ownership/listing-04-03/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-03/src/main.rs @@ -10,7 +10,7 @@ fn main() { // 但 i32 是 Copy 的,所以在后面可继续使用 x } // 这里, x 先移出了作用域,然后是 s。但因为 s 的值已被移走, -// 所以不会有特殊操作 + // 所以不会有特殊操作 fn takes_ownership(some_string: String) { // some_string 进入作用域 println!("{}", some_string); diff --git a/listings/ch04-understanding-ownership/listing-04-04/src/main.rs b/listings/ch04-understanding-ownership/listing-04-04/src/main.rs index d1c1f74..8dd5b47 100644 --- a/listings/ch04-understanding-ownership/listing-04-04/src/main.rs +++ b/listings/ch04-understanding-ownership/listing-04-04/src/main.rs @@ -8,9 +8,9 @@ fn main() { // takes_and_gives_back 中, // 它也将返回值移给 s3 } // 这里, s3 移出作用域并被丢弃。s2 也移出作用域,但已被移走, -// 所以什么也不会发生。s1 移出作用域并被丢弃 + // 所以什么也不会发生。s1 移出作用域并被丢弃 -fn gives_ownership() -> String { // gives_ownership 将返回值移动给 +fn gives_ownership() -> String { // gives_ownership 将返回值移动给 // 调用它的函数 let some_string = String::from("yours"); // some_string 进入作用域 diff --git a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs index d39c64a..b750308 100644 --- a/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs +++ b/listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs @@ -7,7 +7,7 @@ fn main() { } // ANCHOR: here -fn calculate_length(s: &String) -> usize { // s is a reference to a String +fn calculate_length(s: &String) -> usize { // s 是对 String 的引用 s.len() } // 这里,s 离开了作用域。但因为它并不拥有引用值的所有权, // 所以什么也不会发生