affs_read/
error.rs

1//! Error types for AFFS operations.
2
3use core::fmt;
4
5/// Error type for AFFS operations.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum AffsError {
8    /// Block read failed.
9    BlockReadError,
10    /// Invalid DOS type signature.
11    InvalidDosType,
12    /// Invalid block type.
13    InvalidBlockType,
14    /// Invalid secondary type.
15    InvalidSecType,
16    /// Checksum verification failed.
17    ChecksumMismatch,
18    /// Block number out of valid range.
19    BlockOutOfRange,
20    /// Entry not found.
21    EntryNotFound,
22    /// Name too long (max 30 characters).
23    NameTooLong,
24    /// Invalid filesystem state.
25    InvalidState,
26    /// End of file reached.
27    EndOfFile,
28    /// Not a file entry.
29    NotAFile,
30    /// Not a directory entry.
31    NotADirectory,
32    /// Buffer too small.
33    BufferTooSmall,
34    /// Invalid data block sequence.
35    InvalidDataSequence,
36}
37
38impl fmt::Display for AffsError {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            Self::BlockReadError => write!(f, "block read error"),
42            Self::InvalidDosType => write!(f, "invalid DOS type signature"),
43            Self::InvalidBlockType => write!(f, "invalid block type"),
44            Self::InvalidSecType => write!(f, "invalid secondary type"),
45            Self::ChecksumMismatch => write!(f, "checksum mismatch"),
46            Self::BlockOutOfRange => write!(f, "block out of range"),
47            Self::EntryNotFound => write!(f, "entry not found"),
48            Self::NameTooLong => write!(f, "name too long"),
49            Self::InvalidState => write!(f, "invalid filesystem state"),
50            Self::EndOfFile => write!(f, "end of file"),
51            Self::NotAFile => write!(f, "not a file"),
52            Self::NotADirectory => write!(f, "not a directory"),
53            Self::BufferTooSmall => write!(f, "buffer too small"),
54            Self::InvalidDataSequence => write!(f, "invalid data block sequence"),
55        }
56    }
57}
58
59#[cfg(feature = "std")]
60impl std::error::Error for AffsError {}
61
62/// Result type for AFFS operations.
63pub type Result<T> = core::result::Result<T, AffsError>;