tree_buf/internal/
error.rs1use std::fmt::{Debug, Display, Formatter};
2
3#[cfg(feature = "decode")]
4#[derive(Debug, PartialEq, Eq, Clone)]
5pub enum DecodeError {
6 SchemaMismatch,
7 InvalidFormat,
13}
14
15use coercible_errors::coercible_errors;
16coercible_errors!(DecodeError);
17
18#[cfg(feature = "decode")]
19impl Display for DecodeError {
20 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
21 match self {
22 DecodeError::SchemaMismatch => f.write_str("The expected schema did not match that in the document."),
23 DecodeError::InvalidFormat => f.write_str("The format was not a valid Tree-Buf"),
24 }
25 }
26}
27
28#[cfg(feature = "decode")]
29impl std::error::Error for DecodeError {}
30
31#[cfg(feature = "decode")]
32impl From<std::str::Utf8Error> for DecodeError {
33 fn from(_value: std::str::Utf8Error) -> Self {
34 DecodeError::InvalidFormat
35 }
36}