1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::io::Error as IOError;

/// Input/output error type
#[derive(Debug)]
pub enum ErrorType<Byte> {
    /// I/O error
    ///
    /// Wraps a [std::io::Error]
    StdIO(IOError),
    /// Short read/write error
    ///
    /// Number of read/written bytes is less than expected according to the format:
    /// for example if input format is binary, number of input bytes must be a multiple of 8 (since
    /// 8 binary digits are needed to code a byte value);
    /// similarly, if output format is hexadecimal, writing a byte value must result in writing 2
    /// bytes (since 2 hexadecimal digits are needed to code a byte value)
    ShortIO { bytes: usize, expected: usize },
    /// Invalid byte read or invalid byte value to write
    ///
    /// According to expected input format, a char read from the input can be invalid: f.e. in case
    /// of binary format any character other  than '0' or '1' is invalid.
    /// Depending on output format, not all possible byte values can be represented; f.e. in case
    /// of ASCII format only byte values less than 128 are valid.
    InvalidByte(Byte),
}

/// Input error
///
/// See [ErrorType] for details
///
/// [ErrorType]: ErrorType
pub type InError = ErrorType<char>;
/// Output error
///
/// See [ErrorType] for details
///
/// [ErrorType]: ErrorType
pub type OutError = ErrorType<u8>;

/// The error type returned by [convert].
///
/// [convert]: crate::convert
#[derive(Debug)]
pub enum Error {
    /// Input error
    ///
    /// Error originated in reading or parsing the input
    In(InError),
    /// Output error
    ///
    /// Error originated in parsing or writing the output
    Out(OutError),
}