fix: change 、to .

This commit is contained in:
katopz
2022-11-07 11:06:19 +07:00
parent 14a2600176
commit a46840763e
13 changed files with 105 additions and 105 deletions

View File

@ -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<i32> 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> {

View File

@ -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
/* 移除所有可以消除的生命周期标注 */

View File

@ -13,7 +13,7 @@ fn generic<T>(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;