1use std::fmt;
4
5use crate::{Kind, OrbitalId};
6
7pub type Result<T, E = Error> = std::result::Result<T, E>;
8
9#[non_exhaustive]
13#[derive(Debug)]
14pub enum Error {
15 Stale(OrbitalId),
18 KindMismatch {
20 id: OrbitalId,
21 expected: Kind,
22 },
23 UnknownKind(u8),
25 Malformed(Box<str>),
27 Full {
29 capacity: usize,
30 },
31 EpochExhausted,
33 Io(std::io::Error),
34}
35
36impl fmt::Display for Error {
37 fn fmt(
38 &self,
39 f: &mut fmt::Formatter<'_>,
40 ) -> fmt::Result {
41 match self {
42 Self::Stale(id) => write!(f, "orbital {id} is not in this table"),
43 Self::KindMismatch { id, expected } => {
44 write!(f, "orbital {id} is not {expected}")
45 }
46 Self::UnknownKind(kind) => {
47 write!(f, "unknown orbital kind byte {kind:#04x}")
48 }
49 Self::Malformed(text) => write!(f, "not an orbital id: {text:?}"),
50 Self::Full { capacity } => {
51 write!(f, "orbital table is full: capacity={capacity}")
52 }
53 Self::EpochExhausted => {
54 f.write_str("orbital table epoch is exhausted")
55 }
56 Self::Io(error) => write!(f, "orbital table io error: {error}"),
57 }
58 }
59}
60
61impl std::error::Error for Error {
62 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
63 match self {
64 Self::Io(error) => Some(error),
65 _ => None,
66 }
67 }
68}
69
70impl From<std::io::Error> for Error {
71 fn from(value: std::io::Error) -> Self {
72 Self::Io(value)
73 }
74}