use std::fmt;
use std::fmt::Display;
use super::communicator::Communicator;
use crate::messages::Dispatcher;
#[derive(Debug)]
pub(super) enum Status<const CH: usize> {
Open(Communicator<CH>),
Closed(Dispatcher<CH>),
}
impl<const CH: usize> Status<CH> {
pub(super) fn as_str(&self) -> &str {
match self {
Self::Open(_) => "Open",
Self::Closed(_) => "Closed",
}
}
pub(super) fn dispatcher(&self) -> Dispatcher<CH> {
match self {
Status::Open(communicator) => communicator.get_dispatcher(),
Status::Closed(dispatcher) => dispatcher.clone(), }
}
}
impl<const CH: usize> Display for Status<CH> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "STATUS ({})", self.as_str())
}
}