fix: correct , to .
This commit is contained in:
parent
1a5bdaaf77
commit
14a2600176
|
@ -39,7 +39,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
1,π
|
||||
1. π
|
||||
```rust,editable
|
||||
/* Annotate struct with lifetime:
|
||||
1. `r` and `s` must have different lifetimes
|
||||
|
@ -55,7 +55,7 @@ fn main() {
|
|||
```
|
||||
|
||||
|
||||
2,ππ
|
||||
2. ππ
|
||||
```rust,editable
|
||||
/* Adding trait bounds to make it work */
|
||||
struct ImportantExcerpt<'a> {
|
||||
|
@ -74,7 +74,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
3,ππ
|
||||
3. ππ
|
||||
```rust,editable
|
||||
/* Adding trait bounds to make it work */
|
||||
fn f<'a, 'b>(x: &'a i32, mut y: &'b i32) {
|
||||
|
@ -100,7 +100,7 @@ and could then be used to compare a `&'a T` with any lifetime to an `i32`.
|
|||
|
||||
Only a higher-ranked bound can be used here, because the lifetime of the reference is shorter than any possible lifetime parameter on the function.
|
||||
|
||||
4,πππ
|
||||
4. πππ
|
||||
```rust,editable
|
||||
/* Adding HRTB to make it work!*/
|
||||
fn call_on_ref_zero<'a, F>(f: F) where F: Fn(&'a i32) {
|
||||
|
@ -187,7 +187,7 @@ fn main() {
|
|||
```
|
||||
|
||||
|
||||
5,ππ
|
||||
5. ππ
|
||||
```rust,editable
|
||||
/* Make it work by reordering some code */
|
||||
fn main() {
|
||||
|
@ -235,7 +235,7 @@ struct Ref<'a, T> {
|
|||
|
||||
## A difficult exercise
|
||||
|
||||
6,ππππ
|
||||
6. ππππ
|
||||
```rust,editable
|
||||
/* Make it work */
|
||||
struct Interface<'a> {
|
||||
|
|
|
@ -32,7 +32,7 @@ fn need_static(r : &'static str) {
|
|||
}
|
||||
```
|
||||
|
||||
2, ππππ Another way to make `'static` lifetime is using `Box::leak`
|
||||
2. ππππ Another way to make `'static` lifetime is using `Box::leak`
|
||||
```rust,editable
|
||||
#[derive(Debug)]
|
||||
struct Config {
|
||||
|
@ -59,7 +59,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
3, π `&'static` only indicates that the data can live forever, not the reference. The latter one will be constrained by its scope.
|
||||
3. π `&'static` only indicates that the data can live forever, not the reference. The latter one will be constrained by its scope.
|
||||
```rust,editable
|
||||
fn main() {
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
4, `&'static` can be coerced to a shorter lifetime.
|
||||
4. `&'static` can be coerced to a shorter lifetime.
|
||||
|
||||
**Example**
|
||||
```rust,editable
|
||||
|
@ -112,7 +112,7 @@ As a trait bound, it means the type does not contain any non-static references.
|
|||
It's important to understand this means that any owned data always passes a `'static `lifetime bound, but a reference to that owned data generally does not.
|
||||
|
||||
|
||||
5,ππ
|
||||
5. ππ
|
||||
```rust,editable
|
||||
/* Make it work */
|
||||
use std::fmt::Debug;
|
||||
|
@ -147,7 +147,7 @@ fn main() {
|
|||
```
|
||||
|
||||
|
||||
6,πππ
|
||||
6. πππ
|
||||
```rust,editable
|
||||
use std::fmt::Display;
|
||||
|
||||
|
|
Loadingβ¦
Reference in New Issue