rdif_def/
io.rs

1use core::fmt::Display;
2
3pub type Result<T = ()> = core::result::Result<T, Error>;
4
5/// Io error
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct Error {
8    /// The kind of error
9    pub kind: ErrorKind,
10    /// The position of the valid data
11    pub success_pos: usize,
12}
13
14impl Display for Error {
15    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
16        write!(f, "success pos {}, err:{}", self.success_pos, self.kind)
17    }
18}
19
20impl core::error::Error for Error {}
21
22/// Io error kind
23#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Eq)]
24pub enum ErrorKind {
25    #[error("Other error: {0}")]
26    Other(&'static str),
27    #[error("Permission denied")]
28    PermissionDenied,
29    #[error("Hardware not available")]
30    NotAvailable,
31    #[error("Broken pipe")]
32    BrokenPipe,
33    #[error("Invalid parameter: {name}")]
34    InvalidParameter { name: &'static str },
35    #[error("Invalid data")]
36    InvalidData,
37    #[error("Timed out")]
38    TimedOut,
39    /// This operation was interrupted.
40    ///
41    /// Interrupted operations can typically be retried.
42    #[error("Interrupted")]
43    Interrupted,
44    /// This operation is unsupported on this platform.
45    ///
46    /// This means that the operation can never succeed.
47    #[error("Unsupported")]
48    Unsupported,
49    /// An operation could not be completed, because it failed
50    /// to allocate enough memory.
51    #[error("Out of memory")]
52    OutOfMemory,
53    /// An attempted write could not write any data.
54    #[error("Write zero")]
55    WriteZero,
56}