use core::fmt;
use crate::Encoding;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EncodeError {
pub encoding: Encoding,
pub code_point: char,
pub index: usize,
}
impl fmt::Display for EncodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{} has no byte for U+{:04X} ({:?}) at index {}",
self.encoding.apple_name(),
self.code_point as u32,
self.code_point,
self.index
)
}
}
impl core::error::Error for EncodeError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DecodeError {
pub encoding: Encoding,
pub byte: u8,
pub index: usize,
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{} has no character for byte {:#04X} at index {}",
self.encoding.apple_name(),
self.byte,
self.index
)
}
}
impl core::error::Error for DecodeError {}