doc: update rust.md (#178)

* doc: match let

* update
This commit is contained in:
fw_qaq 2022-11-26 12:52:50 -05:00 committed by GitHub
parent 5b71225628
commit 9751df06b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}");