Skip to main content

ids_rs/
error.rs

1//! Error types for PCI database operations.
2
3use core::fmt;
4
5/// Errors that can occur during PCI database parsing or querying.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum PciError {
8    /// Invalid format in the PCI IDs file
9    InvalidFormat,
10    /// Invalid hexadecimal value
11    InvalidHexValue,
12    /// Invalid indentation level
13    InvalidIndentation,
14    /// Unexpected end of input
15    UnexpectedEndOfInput,
16    /// Vendor ID not found
17    VendorNotFound,
18    /// Device ID not found
19    DeviceNotFound,
20    /// Device class not found
21    ClassNotFound,
22    /// Subclass not found
23    SubclassNotFound,
24    /// Programming interface not found
25    ProgInterfaceNotFound,
26}
27
28impl fmt::Display for PciError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            PciError::InvalidFormat => write!(f, "Invalid format in PCI IDs file"),
32            PciError::InvalidHexValue => write!(f, "Invalid hexadecimal value"),
33            PciError::InvalidIndentation => write!(f, "Invalid indentation level"),
34            PciError::UnexpectedEndOfInput => write!(f, "Unexpected end of input"),
35            PciError::VendorNotFound => write!(f, "Vendor ID not found"),
36            PciError::DeviceNotFound => write!(f, "Device ID not found"),
37            PciError::ClassNotFound => write!(f, "Device class not found"),
38            PciError::SubclassNotFound => write!(f, "Subclass not found"),
39            PciError::ProgInterfaceNotFound => write!(f, "Programming interface not found"),
40        }
41    }
42}
43
44/// Result type for PCI database operations.
45pub type PciResult<T> = Result<T, PciError>;