use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
InvalidTypeString {
signature: String,
offset: usize,
reason: &'static str,
},
TypeMismatch {
expected: String,
found: &'static str,
},
InvalidValue(&'static str),
NotNormal(&'static str),
DepthExceeded,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InvalidTypeString {
signature,
offset,
reason,
} => write!(
f,
"invalid type signature {signature:?} at offset {offset}: {reason}"
),
Error::TypeMismatch { expected, found } => {
write!(f, "value of kind {found} does not match type {expected:?}")
}
Error::InvalidValue(reason) => write!(f, "unrepresentable value: {reason}"),
Error::NotNormal(reason) => write!(f, "data is not normal-form GVariant: {reason}"),
Error::DepthExceeded => write!(f, "container nesting exceeds the supported depth"),
}
}
}
impl std::error::Error for Error {}
pub type Result<T> = std::result::Result<T, Error>;