use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DecodeError {
Truncated,
InvalidCodepoint,
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Truncated => write!(f, "stringcue data ends mid-codepoint"),
Self::InvalidCodepoint => write!(f, "stringcue data is not valid unicode"),
}
}
}
impl core::error::Error for DecodeError {}
#[cfg(test)]
mod tests {
use super::*;
use alloc::string::ToString;
#[test]
fn display_mentions_the_problem() {
assert_eq!(
DecodeError::Truncated.to_string(),
"stringcue data ends mid-codepoint"
);
}
#[test]
fn is_std_error() {
fn assert_error<E: core::error::Error>(_: &E) {}
assert_error(&DecodeError::InvalidCodepoint);
}
}