1804060c8SJoel Dice mod bindings {
2804060c8SJoel Dice     wit_bindgen::generate!({
3804060c8SJoel Dice         path: "../misc/component-async-tests/wit",
4804060c8SJoel Dice         world: "closed-streams",
5804060c8SJoel Dice         async: true,
6804060c8SJoel Dice     });
7804060c8SJoel Dice 
8804060c8SJoel Dice     use super::Component;
9804060c8SJoel Dice     export!(Component);
10804060c8SJoel Dice }
11804060c8SJoel Dice 
12804060c8SJoel Dice use {
13804060c8SJoel Dice     bindings::exports::local::local::closed::Guest,
145764da5fSJoel Dice     std::mem,
15*1047b511SAlex Crichton     wit_bindgen::{FutureReader, StreamReader, StreamResult},
16804060c8SJoel Dice };
17804060c8SJoel Dice 
18804060c8SJoel Dice struct Component;
19804060c8SJoel Dice 
20804060c8SJoel Dice impl Guest for Component {
read_stream(mut rx: StreamReader<u8>, expected: Vec<u8>)21804060c8SJoel Dice     async fn read_stream(mut rx: StreamReader<u8>, expected: Vec<u8>) {
225764da5fSJoel Dice         let mut buffer = Vec::with_capacity(expected.len());
235764da5fSJoel Dice         loop {
245764da5fSJoel Dice             let (result, buf) = rx.read(mem::replace(&mut buffer, Vec::new())).await;
255764da5fSJoel Dice             buffer = buf;
265764da5fSJoel Dice             if !matches!(result, StreamResult::Complete(_)) {
275764da5fSJoel Dice                 break;
285764da5fSJoel Dice             }
295764da5fSJoel Dice         }
305764da5fSJoel Dice         assert_eq!(buffer, expected);
31804060c8SJoel Dice     }
32804060c8SJoel Dice 
read_future(rx: FutureReader<u8>, expected: u8, _rx_ignored: FutureReader<u8>)33804060c8SJoel Dice     async fn read_future(rx: FutureReader<u8>, expected: u8, _rx_ignored: FutureReader<u8>) {
34804060c8SJoel Dice         assert_eq!(rx.await, expected);
35804060c8SJoel Dice     }
36a822bb26SJoel Dice 
read_future_post_return( rx: FutureReader<u8>, expected: u8, _rx_ignored: FutureReader<u8>, )37a822bb26SJoel Dice     async fn read_future_post_return(
38a822bb26SJoel Dice         rx: FutureReader<u8>,
39a822bb26SJoel Dice         expected: u8,
40a822bb26SJoel Dice         _rx_ignored: FutureReader<u8>,
41a822bb26SJoel Dice     ) {
42*1047b511SAlex Crichton         wit_bindgen::spawn(async move {
43a822bb26SJoel Dice             assert_eq!(rx.await, expected);
44a822bb26SJoel Dice         });
45a822bb26SJoel Dice     }
46804060c8SJoel Dice }
47804060c8SJoel Dice 
48804060c8SJoel Dice // Unused function; required since this file is built as a `bin`:
main()49804060c8SJoel Dice fn main() {}
50