mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Split code example into individual match cases; add code for example
This commit is contained in:
@@ -387,12 +387,6 @@ TODO
|
||||
|
||||
|
||||
```rust
|
||||
impl Future for ExampleStateMachine {
|
||||
type Output = String; // return type of `example`
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
loop {
|
||||
match self { // TODO: handle pinning
|
||||
ExampleStateMachine::Start(state) => {
|
||||
// from body of `example`
|
||||
let foo_txt_future = async_read_file("foo.txt");
|
||||
@@ -403,6 +397,8 @@ impl Future for ExampleStateMachine {
|
||||
};
|
||||
*self = ExampleStateMachine::WaitingOnFooTxt(state);
|
||||
}
|
||||
```
|
||||
```rust
|
||||
ExampleStateMachine::WaitingOnFooTxt(state) => {
|
||||
match state.foo_txt_future.poll(cx) {
|
||||
Poll::Pending => return Poll::Pending,
|
||||
@@ -423,6 +419,8 @@ impl Future for ExampleStateMachine {
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
```rust
|
||||
ExampleStateMachine::WaitingOnFooTxt(state) => {
|
||||
match state.bar_txt_future.poll(cx) {
|
||||
match state.bar_txt_future.poll(cx) {
|
||||
@@ -435,12 +433,19 @@ impl Future for ExampleStateMachine {
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
```rust
|
||||
ExampleStateMachine::End(_) => {
|
||||
panic!("poll called after Poll::Ready was returned");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```rust
|
||||
fn example(min_len: usize) -> ExampleStateMachine {
|
||||
ExampleStateMachine::Start(StartState {
|
||||
min_len,
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user