Skip to content

Commit 5ebf95d

Browse files
committed
Add WriteError variant for custom errors
Signed-off-by: Facundo Tuesca <[email protected]>
1 parent 4eaf45f commit 5ebf95d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/writer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ use alloc::{fmt, vec};
88
#[derive(PartialEq, Eq, Debug)]
99
pub enum WriteError {
1010
AllocationError,
11+
CustomError(String),
1112
}
1213

1314
impl fmt::Display for WriteError {
1415
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1516
match self {
1617
WriteError::AllocationError => write!(f, "allocation error"),
18+
WriteError::CustomError(s) => write!(f, "{s}"),
1719
}
1820
}
1921
}
@@ -788,5 +790,9 @@ mod tests {
788790
fn test_write_error_display() {
789791
use alloc::string::ToString;
790792
assert_eq!(&WriteError::AllocationError.to_string(), "allocation error");
793+
assert_eq!(
794+
&WriteError::CustomError("my error".to_string()).to_string(),
795+
"my error"
796+
);
791797
}
792798
}

0 commit comments

Comments
 (0)