use std::str::Utf8Error;
use crate::tag::Tag;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Unexpected negative length {0}")]
UnexpectedNegativeLength(i32),
#[error("Wrong tag {0}")]
WrongTag(u8),
#[error("Symbol is invalid utf8 {0}")]
SymbolInvalidUTF8(Utf8Error),
#[error("Unresolved symlink {0}")]
UnresolvedSymlink(usize),
#[error("Unresolved Object link {0}")]
UnresolvedObjectlink(usize),
#[error("Float mantissa too long")]
ParseFloatMantissaTooLong,
#[error("Expected a symbol got {0:?}")]
ExpectedSymbol(Tag),
#[error("Unsupported data encountered: {0}. This is probably because it does not map well to Rust's type system")]
Unsupported(&'static str),
#[error("End of input.")]
Eof,
#[error("Version error, expected [4, 8], got {0:?}")]
VersionError([u8; 2]),
#[error("Serde error: {0}")]
Message(String),
}
impl serde::ser::Error for Error {
fn custom<T>(msg: T) -> Self
where
T: std::fmt::Display,
{
Error::Message(msg.to_string())
}
}
impl serde::de::Error for Error {
fn custom<T>(msg: T) -> Self
where
T: std::fmt::Display,
{
Error::Message(msg.to_string())
}
}