devpath/
error.rs

1use crate::parser::Invalid;
2use crate::Type;
3
4/// Errors that can occur when parsing device paths
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum Error {
7    /// Unknown sub-type for the given device path type
8    UnknownSubType(Type, u8),
9
10    /// Unknown device path type
11    UnknownType(u8),
12
13    /// Invalid data format
14    Invalid,
15}
16
17impl From<Invalid> for Error {
18    fn from(_: Invalid) -> Self {
19        Self::Invalid
20    }
21}
22
23impl core::error::Error for Error {}
24impl core::fmt::Display for Error {
25    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
26        match self {
27            Self::UnknownSubType(t, st) => write!(f, "unknown {t:?} sub-type: {st}"),
28            Self::UnknownType(t) => write!(f, "unknown device path type: {t}"),
29            Self::Invalid => write!(f, "invalid data format"),
30        }
31    }
32}