Skip to main content

epaper_dithering_core/
error.rs

1use std::fmt;
2
3/// Errors that can occur during dithering operations.
4#[derive(Debug, PartialEq)]
5pub enum DitherError {
6    UnknownColorScheme(u8),
7    UnknownDitherMode(u8),
8}
9
10impl fmt::Display for DitherError {
11    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12        match self {
13            DitherError::UnknownColorScheme(v) => write!(f, "unknown color scheme: {v}"),
14            DitherError::UnknownDitherMode(v) => write!(f, "unknown dither mode: {v}"),
15        }
16    }
17}
18
19impl std::error::Error for DitherError {}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn display_unknown_scheme() {
27        let e = DitherError::UnknownColorScheme(42);
28        let msg = e.to_string();
29        assert!(msg.contains("42"), "message should include the bad value: {msg}");
30    }
31}