Files
moli/moli-bounded-json/src/error.rs
T
2026-08-11 00:10:12 +08:00

28 lines
738 B
Rust

use std::{error::Error, fmt};
#[derive(Debug)]
pub enum BoundedJsonError {
LimitExceeded { limit: usize },
Serialization(serde_json::Error),
}
impl fmt::Display for BoundedJsonError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::LimitExceeded { limit } => {
write!(formatter, "serialized JSON exceeds {limit} bytes")
}
Self::Serialization(error) => error.fmt(formatter),
}
}
}
impl Error for BoundedJsonError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::LimitExceeded { .. } => None,
Self::Serialization(error) => Some(error),
}
}
}