iconv_native/
error.rs

1use core::fmt;
2
3#[cfg(doc)]
4use crate::{convert, convert_lossy, decode, decode_lossy};
5
6/// Error representation for [`decode`] and [`convert`].
7#[derive(Debug, PartialEq, Eq)]
8pub enum ConvertError {
9    /// The encodings provided or the specific conversion pair is not supported
10    /// by the implementation.
11    UnknownConversion,
12    /// The input data contains invalid data for the given encoding, or the
13    /// input data contains a character that is not representable in the target
14    /// encoding.
15    InvalidInput,
16}
17
18/// Error representation for [`decode_lossy`] and [`convert_lossy`].
19#[derive(Debug, PartialEq, Eq)]
20pub enum ConvertLossyError {
21    /// The encodings provided or the specific conversion pair is not supported
22    /// by the implementation.
23    UnknownConversion,
24}
25
26impl fmt::Display for ConvertError {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        f.write_str(match self {
29            ConvertError::UnknownConversion => "invalid from_encoding or to_encoding",
30            ConvertError::InvalidInput => "input contains invalid data for the given from_encoding",
31        })
32    }
33}
34
35impl fmt::Display for ConvertLossyError {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        f.write_str(match self {
38            ConvertLossyError::UnknownConversion => "invalid from_encoding or to_encoding",
39        })
40    }
41}
42
43impl From<ConvertLossyError> for ConvertError {
44    fn from(err: ConvertLossyError) -> Self {
45        match err {
46            ConvertLossyError::UnknownConversion => ConvertError::UnknownConversion,
47        }
48    }
49}