bread_cli/
error.rs

1use std::io::Error as IOError;
2
3/// Input/output error type
4#[derive(Debug)]
5pub enum ErrorType<Byte> {
6    /// I/O error
7    ///
8    /// Wraps a [std::io::Error]
9    StdIO(IOError),
10    /// Short read/write error
11    ///
12    /// Number of read/written bytes is less than expected according to the format:
13    /// for example if input format is binary, number of input bytes must be a multiple of 8 (since
14    /// 8 binary digits are needed to code a byte value);
15    /// similarly, if output format is hexadecimal, writing a byte value must result in writing 2
16    /// bytes (since 2 hexadecimal digits are needed to code a byte value)
17    ShortIO { bytes: usize, expected: usize },
18    /// Invalid byte read or invalid byte value to write
19    ///
20    /// According to expected input format, a char read from the input can be invalid: f.e. in case
21    /// of binary format any character other  than '0' or '1' is invalid.
22    /// Depending on output format, not all possible byte values can be represented; f.e. in case
23    /// of ASCII format only byte values less than 128 are valid.
24    InvalidByte(Byte),
25}
26
27/// Input error
28///
29/// See [ErrorType] for details
30///
31/// [ErrorType]: ErrorType
32pub type InError = ErrorType<char>;
33/// Output error
34///
35/// See [ErrorType] for details
36///
37/// [ErrorType]: ErrorType
38pub type OutError = ErrorType<u8>;
39
40/// The error type returned by [convert].
41///
42/// [convert]: crate::convert
43#[derive(Debug)]
44pub enum Error {
45    /// Input error
46    ///
47    /// Error originated in reading or parsing the input
48    In(InError),
49    /// Output error
50    ///
51    /// Error originated in parsing or writing the output
52    Out(OutError),
53}