serial_line_ip/
error.rs

1//! Possible SLIP encoding and decoding errors
2
3use core::fmt;
4
5/// Type alias for handling SLIP errors.
6pub type Result<T> = core::result::Result<T, self::Error>;
7
8/// Errors encountered by SLIP.
9#[derive(Debug)]
10pub enum Error {
11    // Encoder errors
12    /// The encoder does not have enough space to write the SLIP header.
13    NoOutputSpaceForHeader,
14    /// The encoder does not have enough space to write the final SLIP end byte.
15    NoOutputSpaceForEndByte,
16
17    // Decoder errors
18    /// The decoder cannot process the SLIP header.
19    BadHeaderDecode,
20    /// The decoder cannot process the SLIP escape sequence.
21    BadEscapeSequenceDecode,
22}
23
24impl fmt::Display for Error {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        f.write_str(match self {
27            Error::NoOutputSpaceForHeader => "insufficient space in output buffer for header",
28            Error::NoOutputSpaceForEndByte => "insufficient space in output buffer for end byte",
29            Error::BadHeaderDecode => "malformed header",
30            Error::BadEscapeSequenceDecode => "malformed escape sequence",
31        })
32    }
33}