sct_reader/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::fmt::Display;

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum Error {
    MissingMetadata,
    IoError,
    InvalidColourDefinition,
    InvalidFileSection,
    InvalidCoordinate,
    SectorInfoError,
    InvalidAirspaceClass,
    InvalidWaypoint,
    InvalidPosition,
    InvalidRunway,
    InvalidHeading,
    InvalidVorOrNdb,
    InvalidFix,
    InvalidArtccEntry,
    InvalidSidStarEntry,
    InvalidGeoEntry,
    InvalidRegion,
    InvalidLabel,
}

impl Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Self::MissingMetadata => "Missing metadata",
                Self::IoError => "Unable to read the source",
                Self::InvalidColourDefinition => "Invalid colour definition",
                Self::InvalidFileSection => "Invalid file section",
                Self::InvalidCoordinate => "Invalid coordinate",
                Self::SectorInfoError => "Sector information error",
                Self::InvalidAirspaceClass => "Invalid airspace class",
                Self::InvalidWaypoint => "Invalid waypoint",
                Self::InvalidPosition => "Invalid position",
                Self::InvalidRunway => "Invalid runway",
                Self::InvalidHeading => "Invalid heading",
                Self::InvalidVorOrNdb => "Invalid VOR or NDB",
                Self::InvalidFix => "Invalid fix",
                Self::InvalidArtccEntry => "Invalid ARTCC entry",
                Self::InvalidSidStarEntry => "Invalid SID / STAR entry",
                Self::InvalidGeoEntry => "Invalid geo Entry",
                Self::InvalidRegion => "Invalid region",
                Self::InvalidLabel => "Invalid label",
            }
        )
    }
}

impl std::error::Error for Error {}

impl From<std::io::Error> for Error {
    fn from(_: std::io::Error) -> Self {
        Self::IoError
    }
}