1use std::fmt;
5
6pub type Result<T, E = Error> = std::result::Result<T, E>;
7
8#[derive(Debug)]
9pub enum Error {
10 AlreadyJoined { name: &'static str },
12
13 EmptyFleet,
15
16 NodeOutsideFleet { node_id: u16, fleet_capacity: u16 },
18
19 Io(std::io::Error)
21}
22
23impl fmt::Display for Error {
24 fn fmt(
25 &self,
26 f: &mut fmt::Formatter<'_>
27 ) -> fmt::Result {
28 match self {
29 Self::AlreadyJoined { name } => {
30 write!(f, "fleet '{name}' has already been joined in this process")
31 }
32 Self::EmptyFleet => {
33 write!(f, "fleet_capacity must be ≥ 1; Orbit needs at least one node lane")
34 }
35 Self::NodeOutsideFleet { node_id, fleet_capacity } => {
36 write!(f, "node_id {node_id} is outside fleet_capacity {fleet_capacity}")
37 }
38 Self::Io(err) => write!(f, "orbit io error: {err}")
39 }
40 }
41}
42
43impl std::error::Error for Error {
44 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
45 match self {
46 Self::Io(err) => Some(err),
47 _ => None
48 }
49 }
50}