use super::{PortDirection, PortState};
use dogma::{MaybeLabeled, MaybeNamed};
pub trait Port<T: Send>: MaybeNamed + MaybeLabeled {
fn close(&mut self);
fn direction(&self) -> PortDirection;
fn state(&self) -> PortState;
fn is_input(&self) -> bool {
self.direction().is_input()
}
fn is_output(&self) -> bool {
self.direction().is_output()
}
fn is_unconnected(&self) -> bool {
self.state().is_unconnected()
}
fn is_connected(&self) -> bool {
self.state().is_connected()
}
fn is_disconnected(&self) -> bool {
self.state().is_disconnected()
}
fn is_closed(&self) -> bool {
self.state().is_closed()
}
fn capacity(&self) -> Option<usize> {
None }
fn max_capacity(&self) -> Option<usize> {
None }
}
impl<T: Send> core::fmt::Debug for &dyn Port<T> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Port")
.field("name", &self.name())
.field("state", &self.state())
.finish()
}
}