Skip to content

Commit

Permalink
sl-std: impl Display for bitreader::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed Aug 10, 2024
1 parent 448a47d commit 6108bde
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/sl-std/src/bitreader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

/// Wraps a byte buffer to allow reading individual bits
#[derive(Debug)]
pub struct BitReader<'a> {
Expand Down Expand Up @@ -114,6 +116,16 @@ impl<'a> BitReader<'a> {
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TooLargeRead => "attempting to read too many bits at once".fmt(f),
Self::UnalignedRead => "attempting to read bytes from an unaligned position".fmt(f),
Self::UnexpectedEOF => "unexpected end of file".fmt(f),
}
}
}

#[cfg(test)]
mod tests {
use super::BitReader;
Expand Down

0 comments on commit 6108bde

Please sign in to comment.