Skip to content

Commit

Permalink
Implement core::fmt::Display for Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Schievink authored and mvertescher committed Mar 26, 2021
1 parent f91a062 commit 3cf641a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Possible SLIP encoding and decoding errors
use core::fmt;

/// Type alias for handling SLIP errors.
pub type Result<T> = core::result::Result<T, self::Error>;

Expand All @@ -18,3 +20,14 @@ pub enum Error {
/// The decoder cannot process the SLIP escape sequence.
BadEscapeSequenceDecode,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Error::NoOutputSpaceForHeader => "insufficient space in output buffer for header",
Error::NoOutputSpaceForEndByte => "insufficient space in output buffer for end byte",
Error::BadHeaderDecode => "malformed header",
Error::BadEscapeSequenceDecode => "malformed escape sequence",
})
}
}

0 comments on commit 3cf641a

Please sign in to comment.