mirror of
https://github.com/lexmount/moli.git
synced 2026-09-23 16:01:25 +00:00
28 lines
738 B
Rust
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),
|
|
}
|
|
}
|
|
}
|