use core::fmt;
use alloc::string::String;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct TruncatedJson {
pub buffered: usize,
}
impl fmt::Display for TruncatedJson {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"stream ended with {} buffered byte(s) of an incomplete top-level JSON value",
self.buffered
)
}
}
#[cfg(feature = "std")]
impl std::error::Error for TruncatedJson {}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct MalformedJson {
pub byte: u8,
pub values_emitted: usize,
}
impl fmt::Display for MalformedJson {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"malformed top-level JSON framing: unexpected byte {:?} at depth 0 after {} value(s)",
self.byte as char, self.values_emitted
)
}
}
#[cfg(feature = "std")]
impl std::error::Error for MalformedJson {}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum AccumulateError {
UnexpectedEvent {
got: String,
},
BlockKindMismatch {
index: usize,
expected: &'static str,
actual: &'static str,
},
}
impl fmt::Display for AccumulateError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnexpectedEvent { got } => write!(f, "unexpected event: {got}"),
Self::BlockKindMismatch {
index,
expected,
actual,
} => write!(
f,
"block kind mismatch at content block {index}: expected {expected}, got {actual}"
),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for AccumulateError {}