use std::fmt;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug)]
pub enum Error {
AlreadyJoined { name: &'static str },
EmptyFleet,
NodeOutsideFleet { node_id: u16, fleet_capacity: u16 },
Io(std::io::Error)
}
impl fmt::Display for Error {
fn fmt(
&self,
f: &mut fmt::Formatter<'_>
) -> fmt::Result {
match self {
Self::AlreadyJoined { name } => {
write!(f, "fleet '{name}' has already been joined in this process")
}
Self::EmptyFleet => {
write!(f, "fleet_capacity must be ≥ 1; Orbit needs at least one node lane")
}
Self::NodeOutsideFleet { node_id, fleet_capacity } => {
write!(f, "node_id {node_id} is outside fleet_capacity {fleet_capacity}")
}
Self::Io(err) => write!(f, "orbit io error: {err}")
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(err) => Some(err),
_ => None
}
}
}