Skip to content

Commit

Permalink
doc: update rust.md (jaywcjlove#178)
Browse files Browse the repository at this point in the history
* doc: match let

* update
  • Loading branch information
fwqaaq authored Nov 26, 2022
1 parent 5b71225 commit 9751df0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,25 @@ let (x, _, y) = (1, 2, 3);
println!("{x},{y}");
```

----

```rust
fn get_count_item(s: &str) -> (&str, &str) {
let mut it = s.split(' ');
let (Some(str1),Some(str2)) = (it.next(),it.next()) else {
panic!("Can't segment count item pair");
};
(str1, str2)
}
```

### 函数中的模式匹配

```rust
fn add((x, y): (i32, i32)) -> i32 {
x + y
}

fn main(){
let sum = add(1, 2);
println!("{sum}");
Expand Down

0 comments on commit 9751df0

Please sign in to comment.