bin_encode_decode/common/error/
impl.rs

1use super::*;
2
3/// Provides display formatting for EncodeError.
4///
5/// Implements human-readable error messages for encoding failures.
6impl fmt::Display for EncodeError {
7    /// Formats the EncodeError for display purposes.
8    ///
9    /// # Arguments
10    ///
11    /// - `&mut fmt::Formatter<'_>` - The formatter to use.
12    ///
13    /// # Returns
14    ///
15    /// - `fmt::Result` - Result of the formatting operation.
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            EncodeError::CharsetError => write!(
19                f,
20                "EncodeError: Charset is invalid. Please ensure the charset contains exactly {CHARSET_LEN} unique characters."
21            ),
22        }
23    }
24}
25
26/// Provides display formatting for DecodeError.
27///
28/// Implements human-readable error messages for decoding failures.
29impl fmt::Display for DecodeError {
30    /// Formats the DecodeError for display purposes.
31    ///
32    /// # Arguments
33    ///
34    /// - `&mut fmt::Formatter<'_>` - The formatter to use.
35    ///
36    /// # Returns
37    ///
38    /// - `fmt::Result` - Result of the formatting operation.
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            DecodeError::CharsetError => write!(
42                f,
43                "DecodeError: Charset is invalid. Please ensure the charset contains exactly {CHARSET_LEN} unique characters."
44            ),
45        }
46    }
47}