Skip to content

Commit 6c90721

Browse files
committed
Add note about temporaries
1 parent dc3a39d commit 6c90721

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/doc/book/patterns.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,16 @@ let (x, _) = tuple;
196196
println!("Tuple is: {:?}", tuple);
197197
```
198198

199-
In a similar fashion to `_`, you can use `..` in a pattern to disregard
200-
multiple values:
199+
This also means that any temporary variables will be dropped at the end of the
200+
statement:
201+
202+
```rust
203+
// Here, the String created will be dropped immediately, as it’s not bound:
204+
205+
let _ = String::from(" hello ").trim();
206+
```
207+
208+
You can also use `..` in a pattern to disregard multiple values:
201209

202210
```rust
203211
enum OptionalTuple {

0 commit comments

Comments
 (0)