From a46840763ee86b8db8b1e9c37b08d96d59e9c73d Mon Sep 17 00:00:00 2001 From: katopz Date: Mon, 7 Nov 2022 11:06:19 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20change=20=E3=80=81to=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- en/src/functional-programing/closure.md | 22 +++++++++---------- en/src/functional-programing/iterator.md | 24 ++++++++++----------- en/src/lifetime/basic.md | 18 ++++++++-------- en/src/lifetime/static.md | 2 +- en/src/newtype-sized.md | 18 ++++++++-------- solutions/functional-programing/closure.md | 22 +++++++++---------- solutions/functional-programing/iterator.md | 24 ++++++++++----------- solutions/lifetime/advance.md | 12 +++++------ solutions/lifetime/static.md | 8 +++---- solutions/newtype-sized.md | 18 ++++++++-------- zh-CN/src/lifetime/advance.md | 12 +++++------ zh-CN/src/lifetime/basic.md | 18 ++++++++-------- zh-CN/src/lifetime/static.md | 12 +++++------ 13 files changed, 105 insertions(+), 105 deletions(-) diff --git a/en/src/functional-programing/closure.md b/en/src/functional-programing/closure.md index 25b77ac..272b84c 100644 --- a/en/src/functional-programing/closure.md +++ b/en/src/functional-programing/closure.md @@ -41,7 +41,7 @@ Closures can capture variables by borrowing or moving. But they prefer to captur - by mutable reference: `&mut T` - by value: `T` -1ใ€๐ŸŒŸ +1. ๐ŸŒŸ ```rust,editable /* Make it work with least changing */ fn main() { @@ -60,7 +60,7 @@ fn main() { } ``` -2ใ€๐ŸŒŸ๐ŸŒŸ +2. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Make it work - Dont use `_reborrow` and `_count_reborrowed` @@ -89,7 +89,7 @@ fn main() { } ``` -3ใ€๐ŸŒŸ๐ŸŒŸ +3. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Make it work in two ways, none of them is to remove `take(movable)` away from the code */ @@ -132,7 +132,7 @@ let add_one_v3 = |x| { x + 1 }; let add_one_v4 = |x| x + 1 ; ``` -4ใ€๐ŸŒŸ +4. ๐ŸŒŸ ```rust,editable fn main() { let example_closure = |x| x; @@ -151,7 +151,7 @@ When taking a closure as an input parameter, the closure's complete type must be - FnMut: the closure uses the captured value by mutable reference (&mut T) - FnOnce: the closure uses the captured value by value (T) -5ใ€๐ŸŒŸ๐ŸŒŸ +5. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Make it work by change the trait bound, in two ways*/ fn fn_once(func: F) @@ -168,7 +168,7 @@ fn main() { } ``` -6ใ€ ๐ŸŒŸ๐ŸŒŸ +6. ๐ŸŒŸ๐ŸŒŸ ```rust,editable fn main() { let mut s = String::new(); @@ -198,7 +198,7 @@ Which trait to use is determined by what the closure does with captured value. This is because if a move is possible, then any type of borrow should also be possible. Note that the reverse is not true. If the parameter is annotated as `Fn`, then capturing variables by `&mut T` or `T` are not allowed. -7ใ€๐ŸŒŸ๐ŸŒŸ +7. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Fill in the blank */ @@ -285,7 +285,7 @@ fn exec(f: F) { } ``` -8ใ€๐ŸŒŸ๐ŸŒŸ +8. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Fill in the blank */ fn main() { @@ -305,7 +305,7 @@ fn exec<'a, F: __>(mut f: F) { ## Input functions Since closure maybe used as arguments, you might wonder can we use functions as arguments too? And indeed they can. -9ใ€๐ŸŒŸ๐ŸŒŸ +9. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Implement `call_me` to make it work */ @@ -328,7 +328,7 @@ fn main() { ## Closure as return types Returning a closure is much harder than you may thought of. -10ใ€๐ŸŒŸ๐ŸŒŸ +10. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Fill in the blank using two approches, and fix the errror */ @@ -347,7 +347,7 @@ fn main() { } ``` -11ใ€๐ŸŒŸ๐ŸŒŸ +11. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Fill in the blank and fix the error*/ fn factory(x:i32) -> __ { diff --git a/en/src/functional-programing/iterator.md b/en/src/functional-programing/iterator.md index 211ab75..b010fef 100644 --- a/en/src/functional-programing/iterator.md +++ b/en/src/functional-programing/iterator.md @@ -23,7 +23,7 @@ fn main() { } ``` -1ใ€๐ŸŒŸ +1. ๐ŸŒŸ ```rust,editable /* Refactoring the following code using iterators */ fn main() { @@ -34,7 +34,7 @@ fn main() { } ``` -2ใ€ ๐ŸŒŸ One of the easiest ways to create an iterator is to use the range notion: `a..b`. +2. ๐ŸŒŸ One of the easiest ways to create an iterator is to use the range notion: `a..b`. ```rust,editable /* Fill in the blank */ fn main() { @@ -61,7 +61,7 @@ pub trait Iterator { And we can call the `next` method on iterators directly. -3ใ€๐ŸŒŸ๐ŸŒŸ +3. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Fill the blanks and fix the errors. Using two ways if possible */ @@ -83,7 +83,7 @@ In the previous section, we have mentioned that `for` will apply the `into_iter` - `iter`, this borrows each element of the collection through each iteration, thus leaving the collection untouched and available for reuse after the loop - `iter_mut`, this mutably borrows each element of the collection, allowing for the collection to be modified in place. -4ใ€๐ŸŒŸ +4. ๐ŸŒŸ ```rust,editable /* Make it work */ fn main() { @@ -96,7 +96,7 @@ fn main() { } ``` -5ใ€๐ŸŒŸ +5. ๐ŸŒŸ ```rust,editable /* Fill in the blank */ fn main() { @@ -113,7 +113,7 @@ fn main() { } ``` -6ใ€๐ŸŒŸ๐ŸŒŸ +6. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Fill in the blank */ fn main() { @@ -169,7 +169,7 @@ fn main() { } ``` -7ใ€๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ +7. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ```rust,editable struct Fibonacci { curr: u32, @@ -208,7 +208,7 @@ The `Iterator` trait has a number of methods with default implementations provid ### Consuming adaptors Some of these methods call the method `next`to use up the iterator, so they are called *consuming adaptors*. -8ใ€๐ŸŒŸ๐ŸŒŸ +8. ๐ŸŒŸ๐ŸŒŸ ```rust,edtiable /* Fill in the blank and fix the errors */ fn main() { @@ -229,7 +229,7 @@ fn main() { #### collect Other than converting a collection into an iterator, we can also `collect` the result values into a collection, `collect` will cosume the iterator. -9ใ€๐ŸŒŸ๐ŸŒŸ +9. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Make it work */ use std::collections::HashMap; @@ -253,7 +253,7 @@ Methods allowing you to change one iterator into another iterator are known as * But because **all iterators are lazy**, you have to call one of the consuming adapers to get results from calls to iterator adapters. -10ใ€๐ŸŒŸ๐ŸŒŸ +10. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Fill in the blanks */ fn main() { @@ -265,7 +265,7 @@ fn main() { } ``` -11ใ€๐ŸŒŸ๐ŸŒŸ +11. ๐ŸŒŸ๐ŸŒŸ ```rust /* Fill in the blanks */ use std::collections::HashMap; @@ -281,7 +281,7 @@ fn main() { #### Using closures in iterator adaptors -12ใ€๐ŸŒŸ๐ŸŒŸ +12. ๐ŸŒŸ๐ŸŒŸ ```rust /* Fill in the blanks */ #[derive(PartialEq, Debug)] diff --git a/en/src/lifetime/basic.md b/en/src/lifetime/basic.md index e372bc7..70b9eb2 100644 --- a/en/src/lifetime/basic.md +++ b/en/src/lifetime/basic.md @@ -2,7 +2,7 @@ The compiler uses lifetime to ensure all borrows are valid. Typically, a variable's lifetime begins when it is created and ends when it is destroyed. ## The scope of lifetime -1ใ€ ๐ŸŒŸ +1. ๐ŸŒŸ ```rust,editable /* Annotate the lifetime of `i` and `borrow2` */ @@ -109,7 +109,7 @@ fn main() { } ``` -3ใ€ ๐ŸŒŸ +3. ๐ŸŒŸ ```rust,editable /* Make it work by adding proper lifetime annotation */ fn longest(x: &str, y: &str) -> &str { @@ -122,7 +122,7 @@ fn longest(x: &str, y: &str) -> &str { fn main() {} ``` -4ใ€๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ +4. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ```rust,editable // `'a` must live longer than the function. // Here, `&String::from("foo")` would create a `String`, followed by a @@ -138,7 +138,7 @@ fn main() { } ``` -5ใ€๐ŸŒŸ๐ŸŒŸ +5. ๐ŸŒŸ๐ŸŒŸ ```rust,editable // `print_refs` takes two references to `i32` which have different // lifetimes `'a` and `'b`. These two lifetimes must both be at @@ -176,7 +176,7 @@ fn main() { ``` #### Structs -6ใ€ ๐ŸŒŸ +6. ๐ŸŒŸ ```rust,editable /* Make it work by adding proper lifetime annotation */ @@ -216,7 +216,7 @@ fn main() { ``` -7ใ€ ๐ŸŒŸ๐ŸŒŸ +7. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Make it work */ @@ -248,7 +248,7 @@ fn main() ``` -8ใ€ ๐ŸŒŸ๐ŸŒŸ +8. ๐ŸŒŸ๐ŸŒŸ ```rust,editable #[derive(Debug)] @@ -297,7 +297,7 @@ fn main() { } ``` -9ใ€๐ŸŒŸ๐ŸŒŸ +9. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Make it work by adding proper lifetime annotations */ struct ImportantExcerpt { @@ -320,7 +320,7 @@ This is known as **Elision**. Elision exist in Rust only because these patterns For a more comprehensive understanding of elision, please see [lifetime elision](https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html#lifetime-elision) in the official book. -10ใ€๐ŸŒŸ๐ŸŒŸ +10. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* Remove all the lifetimes that can be elided */ diff --git a/en/src/lifetime/static.md b/en/src/lifetime/static.md index d7db355..254e787 100644 --- a/en/src/lifetime/static.md +++ b/en/src/lifetime/static.md @@ -15,7 +15,7 @@ As a reference lifetime, `&'static` indicates the data pointed to by the referen -1ใ€๐ŸŒŸ๐ŸŒŸ There are several ways to make a variable with `'static` lifetime, two of them are stored in the read-only memory of the binary. +1. ๐ŸŒŸ๐ŸŒŸ There are several ways to make a variable with `'static` lifetime, two of them are stored in the read-only memory of the binary. ```rust,editable diff --git a/en/src/newtype-sized.md b/en/src/newtype-sized.md index 479885d..ffea9ae 100644 --- a/en/src/newtype-sized.md +++ b/en/src/newtype-sized.md @@ -5,7 +5,7 @@ The orphan rule tells us that we are allowed to implement a trait on a type as l The **newtype pattern** can help us get around this restriction, which involves creating a new type in a **tuple struct**. -1ใ€๐ŸŒŸ +1. ๐ŸŒŸ ```rust,editable use std::fmt; @@ -26,7 +26,7 @@ fn main() { } ``` -2ใ€๐ŸŒŸ Hide the methods of the original type +2. ๐ŸŒŸ Hide the methods of the original type ```rust,editable /* Make it workd */ struct Meters(u32); @@ -41,7 +41,7 @@ fn main() { } ``` -3ใ€๐ŸŒŸ๐ŸŒŸ The `newtype` idiom gives compile time guarantees that the right type of value is suplied to a program. +3. ๐ŸŒŸ๐ŸŒŸ The `newtype` idiom gives compile time guarantees that the right type of value is suplied to a program. ```rust,editable /* Make it work */ struct Years(i64); @@ -74,7 +74,7 @@ fn main() { } ``` -4ใ€๐ŸŒŸ๐ŸŒŸ +4. ๐ŸŒŸ๐ŸŒŸ ```rust,editable use std::ops::Add; use std::fmt::{self, format}; @@ -133,7 +133,7 @@ let y: Meters = 5; println!("x + y = {}", x + y); ``` -5ใ€๐ŸŒŸ +5. ๐ŸŒŸ ```rust,editable enum VeryVerboseEnumOfThingsToDoWithNumbers { Add, @@ -150,7 +150,7 @@ fn main() { } ``` -6ใ€๐ŸŒŸ๐ŸŒŸ There are a few preserved alias in Rust, one of which can be used in `impl` blocks. +6. ๐ŸŒŸ๐ŸŒŸ There are a few preserved alias in Rust, one of which can be used in `impl` blocks. ```rust,editable enum VeryVerboseEnumOfThingsToDoWithNumbers { Add, @@ -170,7 +170,7 @@ impl VeryVerboseEnumOfThingsToDoWithNumbers { ## DST and unsized type These concepts are complicated, so we are not going to explain here, but you can find them in [The Book](https://doc.rust-lang.org/book/ch19-04-advanced-types.html?highlight=DST#dynamically-sized-types-and-the-sized-trait). -7ใ€๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ Array with dynamic length is a Dynamic Sized Type ( DST ), we can't directly use it +7. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ Array with dynamic length is a Dynamic Sized Type ( DST ), we can't directly use it ```rust,editable /* Make it work with const generics */ fn my_function(n: usize) -> [u32; usize] { @@ -183,7 +183,7 @@ fn main() { } ``` -8ใ€๐ŸŒŸ๐ŸŒŸ Slice is unsized type, but the reference of slice is not. +8. ๐ŸŒŸ๐ŸŒŸ Slice is unsized type, but the reference of slice is not. ```rust,editable /* Make it work with slice references */ fn main() { @@ -193,7 +193,7 @@ fn main() { } ``` -9ใ€๐ŸŒŸ๐ŸŒŸ Trait is also a unsized type +9. ๐ŸŒŸ๐ŸŒŸ Trait is also a unsized type ```rust,editable /* Make it work in two ways */ use std::fmt::Display; diff --git a/solutions/functional-programing/closure.md b/solutions/functional-programing/closure.md index 4a8fea2..fd023da 100644 --- a/solutions/functional-programing/closure.md +++ b/solutions/functional-programing/closure.md @@ -1,4 +1,4 @@ -1ใ€ +1. ```rust fn main() { @@ -13,7 +13,7 @@ fn main() { } ``` -2ใ€ +2. ```rust fn main() { @@ -39,7 +39,7 @@ fn main() { } ``` -3ใ€ +3. ```rust fn main() { @@ -85,7 +85,7 @@ fn take(_v: &T) { } ``` -4ใ€ +4. ```rust fn main() { @@ -98,7 +98,7 @@ fn main() { } ``` -5ใ€ +5. ```rust fn fn_once(func: F) @@ -130,7 +130,7 @@ fn main() { } ``` -6ใ€ +6. ```rust fn main() { @@ -148,7 +148,7 @@ fn exec<'a, F: FnMut(&'a str)>(mut f: F) { } ``` -7ใ€ +7. ```rust // A function which takes a closure as an argument and calls it. @@ -203,7 +203,7 @@ fn main() { } ``` -8ใ€ +8. ```rust fn main() { @@ -219,7 +219,7 @@ fn exec<'a, F: FnOnce(&'a str) -> String>(mut f: F) { } ``` -9ใ€ +9. ```rust // Define a function which takes a generic `F` argument @@ -242,7 +242,7 @@ fn main() { } ``` -10ใ€ +10. ```rust /* Fill in the blank and fix the errror */ @@ -277,7 +277,7 @@ fn main() { } ``` -11ใ€ +11. ```rust // Every closure has its own type. Even if one closure has the same representation as another, their types are different. diff --git a/solutions/functional-programing/iterator.md b/solutions/functional-programing/iterator.md index ab61505..be4d8db 100644 --- a/solutions/functional-programing/iterator.md +++ b/solutions/functional-programing/iterator.md @@ -1,4 +1,4 @@ -1ใ€ +1. ```rust fn main() { @@ -9,7 +9,7 @@ fn main() { } ``` -2ใ€ +2. ```rust fn main() { @@ -22,7 +22,7 @@ fn main() { } ``` -3ใ€ +3. ```rust fn main() { @@ -50,7 +50,7 @@ fn main() { } ``` -4ใ€ +4. ```rust fn main() { @@ -63,7 +63,7 @@ fn main() { } ``` -5ใ€ +5. ```rust fn main() { @@ -80,7 +80,7 @@ fn main() { } ``` -6ใ€ +6. ```rust fn main() { @@ -95,7 +95,7 @@ fn main() { } ``` -7ใ€ +7. ```rust struct Fibonacci { @@ -142,7 +142,7 @@ fn main() { } ``` -8ใ€ +8. ```rust fn main() { @@ -159,7 +159,7 @@ fn main() { } ``` -9ใ€ +9. ```rust use std::collections::HashMap; @@ -177,7 +177,7 @@ fn main() { } ``` -10ใ€ +10. ```rust fn main() { @@ -189,7 +189,7 @@ fn main() { } ``` -11ใ€ +11. ```rust use std::collections::HashMap; @@ -202,7 +202,7 @@ fn main() { } ``` -12ใ€ +12. ```rust #[derive(PartialEq, Debug)] diff --git a/solutions/lifetime/advance.md b/solutions/lifetime/advance.md index 033bc0d..6c6e9db 100644 --- a/solutions/lifetime/advance.md +++ b/solutions/lifetime/advance.md @@ -1,4 +1,4 @@ -1ใ€ +1. ```rust struct DoubleRef<'a,'b:'a, T> { @@ -10,7 +10,7 @@ fn main() { } ``` -2ใ€ +2. ```rust struct ImportantExcerpt<'a> { @@ -29,7 +29,7 @@ fn main() { } ``` -3ใ€ +3. ```rust fn f<'a, 'b>(x: &'a i32, mut y: &'b i32) where 'a: 'b { @@ -41,7 +41,7 @@ fn main() { } ``` -4ใ€ +4. ```rust fn call_on_ref_zero(f: F) where for<'a> F: Fn(&'a i32) { @@ -65,7 +65,7 @@ fn call_on_ref_zero(f: F) where F: for<'a> Fn(&'a i32) { } ``` -5ใ€ +5. ```rust fn main() { @@ -80,7 +80,7 @@ fn main() { } ``` -6ใ€ +6. ```rust struct Interface<'b, 'a: 'b> { diff --git a/solutions/lifetime/static.md b/solutions/lifetime/static.md index 8efda9b..832191a 100644 --- a/solutions/lifetime/static.md +++ b/solutions/lifetime/static.md @@ -1,4 +1,4 @@ -1ใ€ +1. ```rust fn main() { @@ -26,7 +26,7 @@ fn need_static(r : &'static str) { } ``` -2ใ€ +2. ```rust #[derive(Debug)] @@ -55,7 +55,7 @@ fn main() { } ``` -3ใ€ +3. ```rust fn main() { @@ -67,7 +67,7 @@ fn main() { } ``` -5ใ€ +5. ```rust use std::fmt::Debug; diff --git a/solutions/newtype-sized.md b/solutions/newtype-sized.md index 2c273ec..d2ecb8f 100644 --- a/solutions/newtype-sized.md +++ b/solutions/newtype-sized.md @@ -1,4 +1,4 @@ -1ใ€ +1. ```rust use std::fmt; @@ -17,7 +17,7 @@ fn main() { } ``` -2ใ€ +2. ```rust struct Meters(u32); @@ -31,7 +31,7 @@ fn main() { } ``` -3ใ€ +3. ```rust struct Years(i64); @@ -64,7 +64,7 @@ fn main() { } ``` -4ใ€Sometimes `newtype` pattern can provide extra readability. +4. Sometimes `newtype` pattern can provide extra readability. ```rust use std::ops::Add; @@ -97,7 +97,7 @@ fn calculate_distance(d1: Meters, d2: Meters) -> Meters { } ``` -5ใ€ +5. ```rust enum VeryVerboseEnumOfThingsToDoWithNumbers { @@ -115,7 +115,7 @@ fn main() { } ``` -6ใ€ +6. ```rust enum VeryVerboseEnumOfThingsToDoWithNumbers { @@ -135,7 +135,7 @@ impl VeryVerboseEnumOfThingsToDoWithNumbers { fn main() {} ``` -7ใ€ +7. ```rust fn my_function() -> [u32; N] { @@ -148,7 +148,7 @@ fn main() { } ``` -8ใ€ +8. ```rust fn main() { @@ -158,7 +158,7 @@ fn main() { } ``` -9ใ€ +9. ```rust use std::fmt::Display; diff --git a/zh-CN/src/lifetime/advance.md b/zh-CN/src/lifetime/advance.md index 7331755..af2991e 100644 --- a/zh-CN/src/lifetime/advance.md +++ b/zh-CN/src/lifetime/advance.md @@ -39,7 +39,7 @@ fn main() { } ``` -1ใ€๐ŸŒŸ +1. ๐ŸŒŸ ```rust,editable /* ไฝฟ็”จ็”Ÿๅ‘ฝๅ‘จๆœŸๆณจ้‡Š็ป“ๆž„ไฝ“ 1. `r` ๅ’Œ `s` ๅฟ…้กปๆ˜ฏไธๅŒ็”Ÿๅ‘ฝๅ‘จๆœŸ @@ -55,7 +55,7 @@ fn main() { ``` -2ใ€๐ŸŒŸ๐ŸŒŸ +2. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ๆทปๅŠ ็ฑปๅž‹็บฆๆŸไฝฟไธ‹้ขไปฃ็ ๆญฃๅธธ่ฟ่กŒ */ struct ImportantExcerpt<'a> { @@ -74,7 +74,7 @@ fn main() { } ``` -3ใ€๐ŸŒŸ๐ŸŒŸ +3. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ๆทปๅŠ ็ฑปๅž‹็บฆๆŸไฝฟไธ‹้ขไปฃ็ ๆญฃๅธธ่ฟ่กŒ */ fn f<'a, 'b>(x: &'a i32, mut y: &'b i32) { @@ -100,7 +100,7 @@ impl<'a> PartialEq for &'a T { ่ฟ™้‡Œๅช่ƒฝไฝฟ็”จๆ›ด้ซ˜็บงๅˆซ็š„็บฆๆŸ๏ผŒๅ› ไธบๅผ•็”จ็š„็”Ÿๅ‘ฝๅ‘จๆœŸๆฏ”ๅ‡ฝๆ•ฐไธŠไปปไฝ•ๅฏ่ƒฝ็š„็”Ÿๅ‘ฝๅ‘จๆœŸๅ‚ๆ•ฐ้ƒฝ็Ÿญใ€‚ -4ใ€๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ +4. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ```rust /* ๆทปๅŠ  HRTB ไฝฟไธ‹้ขไปฃ็ ๆญฃๅธธ่ฟ่กŒ๏ผ */ fn call_on_ref_zero<'a, F>(f: F) where F: Fn(&'a i32) { @@ -188,7 +188,7 @@ fn main() { ``` -5ใ€๐ŸŒŸ๐ŸŒŸ +5. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ้€š่ฟ‡้‡ๆ–ฐๆŽ’ๅบไธ€ไบ›ไปฃ็ ไฝฟไธ‹้ขไปฃ็ ๆญฃๅธธ่ฟ่กŒ */ fn main() { @@ -236,7 +236,7 @@ struct Ref<'a, T> { ## ่‰ฐ้šพ็š„็ปƒไน  -6ใ€๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ +6. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ```rust /* ไฝฟไธ‹้ขไปฃ็ ๆญฃๅธธ่ฟ่กŒ */ struct Interface<'a> { diff --git a/zh-CN/src/lifetime/basic.md b/zh-CN/src/lifetime/basic.md index 1ad41a2..c0f42d5 100644 --- a/zh-CN/src/lifetime/basic.md +++ b/zh-CN/src/lifetime/basic.md @@ -4,7 +4,7 @@ ## ็”Ÿๅ‘ฝๅ‘จๆœŸ็š„่Œƒๅ›ด -1ใ€ ๐ŸŒŸ +1. ๐ŸŒŸ ```rust,editable /* ไธบ `i` ๅ’Œ `borrow2` ๆ ‡ๆณจๅˆ้€‚็š„็”Ÿๅ‘ฝๅ‘จๆœŸ่Œƒๅ›ด */ @@ -106,7 +106,7 @@ fn main() { } ``` -3ใ€ ๐ŸŒŸ +3. ๐ŸŒŸ ```rust,editable /* ๆทปๅŠ ๅˆ้€‚็š„็”Ÿๅ‘ฝๅ‘จๆœŸๆ ‡ๆณจ๏ผŒ่ฎฉไธ‹้ข็š„ไปฃ็ ๅทฅไฝœ */ fn longest(x: &str, y: &str) -> &str { @@ -119,7 +119,7 @@ fn longest(x: &str, y: &str) -> &str { fn main() {} ``` -4ใ€๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ +4. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ไฝฟ็”จไธ‰็งๆ–นๆณ•ไฟฎๅคไธ‹้ข็š„้”™่ฏฏ */ fn invalid_output<'a>() -> &'a String { @@ -130,7 +130,7 @@ fn main() { } ``` -5ใ€๐ŸŒŸ๐ŸŒŸ +5. ๐ŸŒŸ๐ŸŒŸ ```rust,editable // `print_refs` ๆœ‰ไธคไธชๅผ•็”จๅ‚ๆ•ฐ๏ผŒๅฎƒไปฌ็š„็”Ÿๅ‘ฝๅ‘จๆœŸ `'a` ๅ’Œ `'b` ่‡ณๅฐ‘ๅพ—่ทŸๅ‡ฝๆ•ฐๆดปๅพ—ไธ€ๆ ทไน… fn print_refs<'a, 'b>(x: &'a i32, y: &'b i32) { @@ -161,7 +161,7 @@ fn main() { ``` #### Structs -6ใ€ ๐ŸŒŸ +6. ๐ŸŒŸ ```rust,editable /* ๅขžๅŠ ๅˆ้€‚็š„็”Ÿๅ‘ฝๅ‘จๆœŸๆ ‡ๅ‡†๏ผŒ่ฎฉไปฃ็ ๅทฅไฝœ */ @@ -199,7 +199,7 @@ fn main() { ``` -7ใ€ ๐ŸŒŸ๐ŸŒŸ +7. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ่ฎฉไปฃ็ ๅทฅไฝœ */ @@ -229,7 +229,7 @@ fn main() ``` -8ใ€ ๐ŸŒŸ๐ŸŒŸ +8. ๐ŸŒŸ๐ŸŒŸ ```rust,editable #[derive(Debug)] @@ -277,7 +277,7 @@ fn main() { } ``` -9ใ€๐ŸŒŸ๐ŸŒŸ +9. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ๆทปๅŠ ๅˆ้€‚็š„็”Ÿๅ‘ฝๅ‘จๆœŸ่ฎฉไธ‹้ขไปฃ็ ๅทฅไฝœ */ struct ImportantExcerpt { @@ -300,7 +300,7 @@ fn main() {} ่ฟ™็ง่ง„ๅˆ™่ขซ็งฐไธบ็”Ÿๅ‘ฝๅ‘จๆœŸๆถˆ้™ค่ง„ๅˆ™( Elision )๏ผŒ่ฏฅ่ง„ๅˆ™ไน‹ๆ‰€ไปฅๅญ˜ๅœจ๏ผŒไป…ไป…ๆ˜ฏๅ› ไธบ่ฟ™ไบ›ๅœบๆ™ฏๅคช้€š็”จไบ†๏ผŒไธบไบ†ๆ–นไพฟ็”จๆˆท่€Œๅทฒใ€‚ไบ‹ๅฎžไธŠๅฏนไบŽๅ€Ÿ็”จๆฃ€ๆŸฅๅ™จ่€Œ่จ€๏ผŒ่ฏฅๆœ‰็š„็”Ÿๅ‘ฝๅ‘จๆœŸไธ€ไธช้ƒฝไธ่ƒฝๅฐ‘๏ผŒๅชไธ่ฟ‡ๅฏนไบŽ็”จๆˆท่€Œ่จ€๏ผŒๅฏไปฅ็œๅŽปไธ€ไบ›ใ€‚ -10ใ€๐ŸŒŸ๐ŸŒŸ +10. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ็งป้™คๆ‰€ๆœ‰ๅฏไปฅๆถˆ้™ค็š„็”Ÿๅ‘ฝๅ‘จๆœŸๆ ‡ๆณจ */ diff --git a/zh-CN/src/lifetime/static.md b/zh-CN/src/lifetime/static.md index 48a9edd..6642b90 100644 --- a/zh-CN/src/lifetime/static.md +++ b/zh-CN/src/lifetime/static.md @@ -13,7 +13,7 @@ fn generic(x: T) where T: 'static {} ## &'static ไฝœไธบไธ€ไธชๅผ•็”จ็”Ÿๅ‘ฝๅ‘จๆœŸ๏ผŒ`&'static` ่ฏดๆ˜Ž่ฏฅๅผ•็”จๆŒ‡ๅ‘็š„ๆ•ฐๆฎๅฏไปฅ่ทŸ็จ‹ๅบๆดปๅพ—ไธ€ๆ ทไน…๏ผŒไฝ†ๆ˜ฏ่ฏฅๅผ•็”จ็š„็”Ÿๅ‘ฝๅ‘จๆœŸไพ็„ถๆœ‰ๅฏ่ƒฝ่ขซๅผบ่ฝฌไธบไธ€ไธชๆ›ด็Ÿญ็š„็”Ÿๅ‘ฝๅ‘จๆœŸใ€‚ -1ใ€๐ŸŒŸ๐ŸŒŸ ๆœ‰ๅฅฝๅ‡ ็งๆ–นๆณ•ๅฏไปฅๅฐ†ไธ€ไธชๅ˜้‡ๆ ‡่ฎฐไธบ `'static` ็”Ÿๅ‘ฝๅ‘จๆœŸ, ๅ…ถไธญไธค็ง้ƒฝๆ˜ฏๅ’Œไฟๅญ˜ๅœจไบŒ่ฟ›ๅˆถๆ–‡ไปถไธญ็›ธๅ…ณ( ไพ‹ๅฆ‚ๅญ—็ฌฆไธฒๅญ—้ข้‡ๅฐฑๆ˜ฏไฟๅญ˜ๅœจไบŒ่ฟ›ๅˆถๆ–‡ไปถไธญ๏ผŒๅฎƒ็š„็”Ÿๅ‘ฝๅ‘จๆœŸๆ˜ฏ `'static` )ใ€‚ +1. ๐ŸŒŸ๐ŸŒŸ ๆœ‰ๅฅฝๅ‡ ็งๆ–นๆณ•ๅฏไปฅๅฐ†ไธ€ไธชๅ˜้‡ๆ ‡่ฎฐไธบ `'static` ็”Ÿๅ‘ฝๅ‘จๆœŸ, ๅ…ถไธญไธค็ง้ƒฝๆ˜ฏๅ’Œไฟๅญ˜ๅœจไบŒ่ฟ›ๅˆถๆ–‡ไปถไธญ็›ธๅ…ณ( ไพ‹ๅฆ‚ๅญ—็ฌฆไธฒๅญ—้ข้‡ๅฐฑๆ˜ฏไฟๅญ˜ๅœจไบŒ่ฟ›ๅˆถๆ–‡ไปถไธญ๏ผŒๅฎƒ็š„็”Ÿๅ‘ฝๅ‘จๆœŸๆ˜ฏ `'static` )ใ€‚ ```rust,editable @@ -30,7 +30,7 @@ fn need_static(r : &'static str) { } ``` -2ใ€ ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ไฝฟ็”จ `Box::leak` ไนŸๅฏไปฅไบง็”Ÿ `'static` ็”Ÿๅ‘ฝๅ‘จๆœŸ +2. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ไฝฟ็”จ `Box::leak` ไนŸๅฏไปฅไบง็”Ÿ `'static` ็”Ÿๅ‘ฝๅ‘จๆœŸ ```rust,editable #[derive(Debug)] struct Config { @@ -57,7 +57,7 @@ fn main() { } ``` -3ใ€ ๐ŸŒŸ `&'static` ๅช่ƒฝ่ฏดๆ˜Žๅผ•็”จๆŒ‡ๅ‘็š„ๆ•ฐๆฎๆ˜ฏ่ƒฝไธ€็›ดๅญ˜ๆดป็š„๏ผŒไฝ†ๆ˜ฏๅผ•็”จๆœฌ่บซไพ็„ถๅ—้™ไบŽๅฎƒ็š„ไฝœ็”จๅŸŸ +3. ๐ŸŒŸ `&'static` ๅช่ƒฝ่ฏดๆ˜Žๅผ•็”จๆŒ‡ๅ‘็š„ๆ•ฐๆฎๆ˜ฏ่ƒฝไธ€็›ดๅญ˜ๆดป็š„๏ผŒไฝ†ๆ˜ฏๅผ•็”จๆœฌ่บซไพ็„ถๅ—้™ไบŽๅฎƒ็š„ไฝœ็”จๅŸŸ ```rust,editable fn main() { { @@ -72,7 +72,7 @@ fn main() { } ``` -4ใ€ `&'static` ๅฏไปฅ่ขซๅผบ่ฝฌๆˆไธ€ไธช่พƒ็Ÿญ็š„็”Ÿๅ‘ฝๅ‘จๆœŸ +4. `&'static` ๅฏไปฅ่ขซๅผบ่ฝฌๆˆไธ€ไธช่พƒ็Ÿญ็š„็”Ÿๅ‘ฝๅ‘จๆœŸ **Example** ```rust,editable @@ -103,7 +103,7 @@ fn main() { ๅ…ณไบŽ `'static` ็š„็‰นๅพ็บฆๆŸ่ฏฆ็ป†่งฃ้‡Š๏ผŒ่ฏทๅ‚่ง [Rust ่ฏญ่จ€ๅœฃ็ป](https://course.rs/advance/lifetime/static.html#t-static)๏ผŒ่ฟ™้‡Œๅฐฑไธๅ†่ต˜่ฟฐใ€‚ -5ใ€๐ŸŒŸ๐ŸŒŸ +5. ๐ŸŒŸ๐ŸŒŸ ```rust,editable /* ่ฎฉไปฃ็ ๅทฅไฝœ */ use std::fmt::Debug; @@ -137,7 +137,7 @@ fn main() { ``` -6ใ€๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ +6. ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ ```rust,editable use std::fmt::Display;