警告
本文最后更新于 2022-04-24,文中内容可能已过时。
Rust 函数结果作为下一个函数的输入,类似 let vec = "ada".chars().collect::<Vec<char>>();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| fn main() {
let vec = "abc";
let tem = vec.chars().collect::<Vec<char>>();
let a = Foo(1);
let b = a.add_one().add_two();
println!("{:?}", b);
}
#[derive(PartialEq,Debug)]
struct Foo(i32);
impl Foo {
fn add_one(self) -> Bar {
Bar::new(self.0)
}
}
#[derive(PartialEq,Debug)]
struct Bar(i32);
impl Bar {
fn new(i: i32) -> Bar {
Bar(i)
}
fn add_two(self) -> Bar {
Bar(self.0 + 2)
}
}
|