You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/c3.lifetimes.md
+1-23Lines changed: 1 addition & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,8 +53,6 @@ fn take_str(x: &'static str) {
53
53
54
54
## Usage
55
55
56
-
Lifetimes are denoted with an apostrophe. By convention, a lowercase letter is used for naming. Usually **starts with**`'a` and **follows alphabetic order** when we need to add **multiple lifetime** annotations.
As I mentioned earlier, in order to make **common patterns** more ergonomic, Rust allows lifetimes to be **elided/omitted**. This process is called **Lifetime Elision**.
165
-
166
-
💡 For the moment Rust supports Lifetime Elisions only on `fn` definitions. But in the future, it will support for `impl` headers as well.
167
-
168
162
Lifetime annotations of `fn` definitions can be elided
169
163
if its **parameter list** has either,
170
164
171
165
***only one input parameter passes by reference**.
172
-
* a parameter with **either**`&self`**or****&mut self** reference.
166
+
* a parameter with **either `&self`or `&mut self` reference**.
173
167
174
168
```rust
175
169
fntriple(x:&u64) ->u64 { // Only one input parameter passes by reference
@@ -220,22 +214,6 @@ fn main() {
220
214
> * For all other cases, we have to write lifetime annotations manually.
221
215
222
216
223
-
## `'static` Annotations
224
-
225
-
`'static` lifetime annotation is a **reserved** lifetime annotation. These **references are valid for the entire program**. They are saved in the data segment of the binary and the data referred to will never go out of scope.
226
-
227
-
```rust
228
-
staticN:i32=5; // A constant with 'static lifetime
229
-
230
-
leta="Hello, world."; // a: &'static str
231
-
232
-
233
-
fnindex() ->&'staticstr { // No need to mention <'static> ; fn index ̶<̶'̶s̶t̶a̶t̶i̶c̶>̶
234
-
"Hello, world!"
235
-
}
236
-
```
237
-
238
-
239
217
## Few more examples about the usage of Rust lifetimes.
0 commit comments