use thiserror::Error;
#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
pub enum CharsetDecodeErrorKind {
#[error("The encoded text sequence is malformed.")]
MalformedSequence {
value: Option<u32>,
},
#[error("The encoded text sequence is incomplete (required {required} units, available {available} units).")]
IncompleteSequence {
required: usize,
available: usize,
},
#[error("The decoded code point 0x{value:x} is not a valid Unicode scalar value.")]
InvalidCodePoint {
value: u32,
},
}
impl CharsetDecodeErrorKind {
#[must_use]
#[inline]
pub const fn required(self) -> Option<usize> {
match self {
Self::IncompleteSequence { required, .. } => Some(required),
Self::MalformedSequence { .. } | Self::InvalidCodePoint { .. } => None,
}
}
#[must_use]
#[inline]
pub const fn available(self) -> Option<usize> {
match self {
Self::IncompleteSequence { available, .. } => Some(available),
Self::MalformedSequence { .. } | Self::InvalidCodePoint { .. } => None,
}
}
#[must_use]
#[inline]
pub const fn value(self) -> Option<u32> {
match self {
Self::MalformedSequence { value } => value,
Self::InvalidCodePoint { value } => Some(value),
Self::IncompleteSequence { .. } => None,
}
}
}