#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EncodeError {
PayloadTooLarge { max: usize, actual: usize },
LayeredOutputTooLarge { max: usize, actual: usize },
InvalidUtf8,
InvalidContext {
strategy: &'static str,
context: String,
},
InvalidConfig(String),
}
impl std::fmt::Display for EncodeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::PayloadTooLarge { max, actual } => {
write!(f, "payload too large: {actual} bytes (max {max} bytes)")
}
Self::LayeredOutputTooLarge { max, actual } => {
write!(
f,
"layered output too large: {actual} bytes (max {max} bytes)"
)
}
Self::InvalidUtf8 => f.write_str("payload contains invalid UTF-8"),
Self::InvalidContext { strategy, context } => {
write!(f, "strategy {strategy} is not valid in context {context}")
}
Self::InvalidConfig(msg) => write!(f, "invalid config: {msg}"),
}
}
}
impl std::error::Error for EncodeError {}