From 15631b0480fb125f7dd767d8af7c55848e8f7f9d Mon Sep 17 00:00:00 2001 From: ltitanb Date: Thu, 28 Aug 2025 13:23:16 +0100 Subject: [PATCH 1/2] impl `Error` --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 66223cb..e552050 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,3 +69,31 @@ pub enum Error { expected: usize, }, } + +impl core::fmt::Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Error::OutOfBounds { i, len } => { + write!(f, "Index out of bounds: index {}, length {}", i, len) + } + Error::MissingLengthInformation => { + write!( + f, + "BitList does not have a set bit, length cannot be determined" + ) + } + Error::ExcessBits => { + write!(f, "BitList has excess bits set to true") + } + Error::InvalidByteCount { given, expected } => { + write!( + f, + "Invalid byte count: got {}, expected {}", + given, expected + ) + } + } + } +} + +impl core::error::Error for Error {} From 99e40702bf9861b21177cda204f28baa4af143d5 Mon Sep 17 00:00:00 2001 From: ltitanb Date: Thu, 28 Aug 2025 13:25:51 +0100 Subject: [PATCH 2/2] small change --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e552050..24a7c2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,7 @@ impl core::fmt::Display for Error { Error::InvalidByteCount { given, expected } => { write!( f, - "Invalid byte count: got {}, expected {}", + "Invalid byte count: given {}, expected {}", given, expected ) }