use std;
use std::fmt::{self, Display};
use serde::{de, ser};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Clone, Debug, PartialEq)]
pub enum Error {
Message(String),
UnknownSeqLength,
TypeNotSupported,
MalformedData
}
impl ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Message(msg.to_string())
}
}
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Message(msg.to_string())
}
}
impl Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Message(msg) => formatter.write_str(msg),
Error::TypeNotSupported => formatter.write_str("Type is not supported as it not documented in the yellow paper."),
Error::UnknownSeqLength => formatter.write_str("Sequence lenght must be known at compile time."),
Error::MalformedData => formatter.write_str("RLP encoded data is malformed.")
}
}
}
impl std::error::Error for Error {}