preserves/implementations/rust/src/value/error.rs

53 lines
1016 B
Rust

use num::bigint::BigInt;
use crate::value::PlainValue;
#[derive(Debug)]
pub enum Error {
Message(String),
InvalidUnicodeScalar(u32),
NumberTooLarge(BigInt),
CannotDeserializeAny,
Expected(ExpectedKind, PlainValue),
InternalMagicError,
}
#[derive(Debug)]
pub enum ExpectedKind {
Boolean,
Float,
Double,
SignedInteger,
String,
ByteString,
Symbol,
Record,
SimpleRecord(&'static str, Option<usize>),
Option,
Sequence,
Dictionary,
}
pub type Result<T> = std::result::Result<T, Error>;
impl serde::ser::Error for Error {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
Self::Message(msg.to_string())
}
}
impl serde::de::Error for Error {
fn custom<T: std::fmt::Display>(msg: T) -> Self {
Self::Message(msg.to_string())
}
}
impl std::error::Error for Error {}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}