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