mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-07-20 19:35:30 +00:00
@@ -214,7 +214,7 @@ impl<'a> Reader for BufReader<'a> {
|
||||
// 'a is not used in the following methods
|
||||
}
|
||||
|
||||
// can be writting as :
|
||||
// can be writing as :
|
||||
impl Reader for BufReader<'_> {
|
||||
|
||||
}
|
||||
|
@@ -59,11 +59,11 @@ fn main() {
|
||||
```
|
||||
|
||||
## lifetime annotating
|
||||
The **borrow checker uses explicit lifetime annotations** to determine how long a referrence should be valid.
|
||||
The **borrow checker uses explicit lifetime annotations** to determine how long a reference should be valid.
|
||||
|
||||
But for us users, in most cases, there is no need to annotate the lifetime, because there are several elision rules, before learning these rules, we need to know how to annotate lifetime manually.
|
||||
|
||||
#### funtion
|
||||
#### function
|
||||
Ignoring elision rules, lifetimes in function signatures have a few contraints:
|
||||
|
||||
- any reference must have an annotated lifetime
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# &'static and T: 'static
|
||||
`'static` is a reserverd lifetime name, you might have encountered it serveral times:
|
||||
`'static` is a reserved lifetime name, you might have encountered it serveral times:
|
||||
```rust
|
||||
// A reference with 'static lifetime:
|
||||
let s: &'static str = "hello world";
|
||||
|
Reference in New Issue
Block a user