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 {} unique characters.",
21                CHARSET_LEN
22            ),
23        }
24    }
25}
26
27/// Provides display formatting for DecodeError.
28///
29/// Implements human-readable error messages for decoding failures.
30impl fmt::Display for DecodeError {
31    /// Formats the DecodeError for display purposes.
32    ///
33    /// # Arguments
34    ///
35    /// - `&mut fmt::Formatter<'_>` - The formatter to use.
36    ///
37    /// # Returns
38    ///
39    /// - `fmt::Result` - Result of the formatting operation.
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            DecodeError::CharsetError => write!(
43                f,
44                "DecodeError: Charset is invalid. Please ensure the charset contains exactly {} unique characters.",
45                CHARSET_LEN
46            ),
47        }
48    }
49}