docs: adjust sample code comments

This commit is contained in:
YangFong 2022-03-07 19:00:10 +08:00
parent 48486b7bb3
commit 0253dc7a4c
3 changed files with 4 additions and 4 deletions

View File

@ -10,7 +10,7 @@ fn main() {
// 但 i32 是 Copy 的,所以在后面可继续使用 x // 但 i32 是 Copy 的,所以在后面可继续使用 x
} // 这里, x 先移出了作用域,然后是 s。但因为 s 的值已被移走, } // 这里, x 先移出了作用域,然后是 s。但因为 s 的值已被移走,
// 所以不会有特殊操作 // 所以不会有特殊操作
fn takes_ownership(some_string: String) { // some_string 进入作用域 fn takes_ownership(some_string: String) { // some_string 进入作用域
println!("{}", some_string); println!("{}", some_string);

View File

@ -8,7 +8,7 @@ fn main() {
// takes_and_gives_back 中, // takes_and_gives_back 中,
// 它也将返回值移给 s3 // 它也将返回值移给 s3
} // 这里, s3 移出作用域并被丢弃。s2 也移出作用域,但已被移走, } // 这里, s3 移出作用域并被丢弃。s2 也移出作用域,但已被移走,
// 所以什么也不会发生。s1 移出作用域并被丢弃 // 所以什么也不会发生。s1 移出作用域并被丢弃
fn gives_ownership() -> String { // gives_ownership 将返回值移动给 fn gives_ownership() -> String { // gives_ownership 将返回值移动给
// 调用它的函数 // 调用它的函数

View File

@ -7,7 +7,7 @@ fn main() {
} }
// ANCHOR: here // 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.len()
} // 这里s 离开了作用域。但因为它并不拥有引用值的所有权, } // 这里s 离开了作用域。但因为它并不拥有引用值的所有权,
// 所以什么也不会发生 // 所以什么也不会发生