Skip to content

Commit

Permalink
underscore-expr: add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
japm48 authored Mar 3, 2024
1 parent 1afcfd9 commit 3cbbb68
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/expressions/underscore-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ side of an assignment.

Note that this is distinct from the [wildcard pattern](../patterns.md#wildcard-pattern).

An example of an `_` expression:
Examples of `_` expressions:

```rust
let p = (1, 2);
let mut a = 0;
(_, a) = p;

struct Position {
x: u32,
y: u32,
}

Position { x: a, y: _ } = Position{ x: 2, y: 3 };

// unused result, _-assignment used to declare intent and remove a warning
_ = 2 + 2;
// triggers unused_must_use warning
// 2 + 2;
//
// equivalent technique using a wildcard pattern in a let-binding
let _ = 2 + 2;
```

0 comments on commit 3cbbb68

Please sign in to comment.