async_flow/io/
input_port.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::{error::RecvError, io::Port};
4use alloc::boxed::Box;
5use alloc::vec::Vec;
6
7#[async_trait::async_trait]
8pub trait InputPort<T: Send>: Port<T> {
9    /// Checks if this port is empty.
10    fn is_empty(&self) -> bool;
11
12    async fn recv(&mut self) -> Result<Option<T>, RecvError>;
13
14    async fn recv_all(&mut self) -> Result<Vec<T>, RecvError> {
15        let mut inputs = Vec::new();
16        while let Some(input) = self.recv().await? {
17            inputs.push(input);
18        }
19        Ok(inputs)
20    }
21
22    // TODO: recv_event
23    // TODO: recv_deadline
24    // TODO: recv_timeout
25    // TODO: try_recv
26    // TODO: into_stream
27}