69 lines
1.2 KiB
Rust
69 lines
1.2 KiB
Rust
use num_bigint::BigInt;
|
|
use std::convert::From;
|
|
use std::io;
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
Io(io::Error),
|
|
Message(String),
|
|
InvalidUnicodeScalar(u32),
|
|
NumberOutOfRange(BigInt),
|
|
MissingCloseDelimiter,
|
|
MissingItem,
|
|
Expected(ExpectedKind),
|
|
}
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub enum ExpectedKind {
|
|
Boolean,
|
|
Float,
|
|
Double,
|
|
|
|
SignedIntegerI128,
|
|
SignedIntegerU128,
|
|
SignedInteger,
|
|
String,
|
|
ByteString,
|
|
Symbol,
|
|
|
|
Record,
|
|
SimpleRecord(String),
|
|
Sequence,
|
|
Set,
|
|
Dictionary,
|
|
|
|
Embedded,
|
|
|
|
Option,
|
|
UnicodeScalar,
|
|
Annotation,
|
|
}
|
|
|
|
impl From<io::Error> for Error {
|
|
fn from(e: io::Error) -> Self {
|
|
Error::Io(e)
|
|
}
|
|
}
|
|
|
|
impl From<Error> for io::Error {
|
|
fn from(e: Error) -> Self {
|
|
match e {
|
|
Error::Io(ioe) => ioe,
|
|
Error::Message(str) => io::Error::new(io::ErrorKind::Other, str),
|
|
_ => io::Error::new(io::ErrorKind::Other, e),
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
pub fn io_eof() -> io::Error {
|
|
io::Error::new(io::ErrorKind::UnexpectedEof, "EOF")
|
|
}
|