facet_yaml/serialize/
error.rs

1//! Errors from parsing into YAML documents.
2
3/// Any error from serializing YAML.
4pub enum YamlSerError {
5    /// Could not convert number to i64 representation.
6    InvalidNumberToI64Conversion {
7        /// Type of the number that's trying to be converted.
8        source_type: &'static str,
9    },
10    /// Could not convert type to valid YAML key.
11    InvalidKeyConversion {
12        /// Type of the YAML value that's trying to be converted to a key.
13        yaml_type: &'static str,
14    },
15    /// YAML doesn't support byte arrays.
16    UnsupportedByteArray,
17}
18
19impl core::fmt::Display for YamlSerError {
20    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21        match self {
22            Self::InvalidNumberToI64Conversion { source_type } => {
23                write!(f, "Error converting {source_type} to i64, out of range")
24            }
25            Self::InvalidKeyConversion { yaml_type } => {
26                write!(f, "Error converting type {yaml_type} to YAML key")
27            }
28            Self::UnsupportedByteArray => {
29                write!(f, "YAML doesn't support byte arrays")
30            }
31        }
32    }
33}
34
35impl core::error::Error for YamlSerError {}
36
37impl core::fmt::Debug for YamlSerError {
38    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
39        core::fmt::Display::fmt(self, f)
40    }
41}