Skip to content

Commit 3cf641a

Browse files
Jonas Schievinkmvertescher
authored andcommitted
Implement core::fmt::Display for Error
1 parent f91a062 commit 3cf641a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/error.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Possible SLIP encoding and decoding errors
22
3+
use core::fmt;
4+
35
/// Type alias for handling SLIP errors.
46
pub type Result<T> = core::result::Result<T, self::Error>;
57

@@ -18,3 +20,14 @@ pub enum Error {
1820
/// The decoder cannot process the SLIP escape sequence.
1921
BadEscapeSequenceDecode,
2022
}
23+
24+
impl 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+
}

0 commit comments

Comments
 (0)