parent
5b71225628
commit
9751df06b9
13
docs/rust.md
13
docs/rust.md
@ -853,12 +853,25 @@ let (x, _, y) = (1, 2, 3);
|
|||||||
println!("{x},{y}");
|
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
|
```rust
|
||||||
fn add((x, y): (i32, i32)) -> i32 {
|
fn add((x, y): (i32, i32)) -> i32 {
|
||||||
x + y
|
x + y
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
fn main(){
|
||||||
let sum = add(1, 2);
|
let sum = add(1, 2);
|
||||||
println!("{sum}");
|
println!("{sum}");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user