async_flow/io/
port.rs

1// This is free and unencumbered software released into the public domain.
2
3use core::fmt::Debug;
4use dogma::{MaybeLabeled, MaybeNamed};
5
6/// The common interface for ports, whether for input or output.
7pub trait Port<T>: Debug + MaybeNamed + MaybeLabeled {
8    /// Checks if a port is open.
9    fn is_open(&self) -> bool {
10        !self.is_closed()
11    }
12
13    /// Checks if a port is closed.
14    fn is_closed(&self) -> bool;
15
16    /// Closes the port without dropping it.
17    fn close(&mut self);
18
19    /// Returns the remaining buffer capacity of the connection.
20    fn capacity(&self) -> Option<usize> {
21        None // unknown
22    }
23
24    /// Returns the maximum buffer capacity of the connection.
25    fn max_capacity(&self) -> Option<usize> {
26        None // unknown
27    }
28}