refactored errors and ser to support nostd to-buffer encoding
This commit is contained in:
1 parent
c1b1cceaa1
commit
52ab4a1f7b
10 files changed
+170
-127
No files matched your search
+8
-39
@@ -1,51 +1,20 @@
|
||||
use std;
|
||||
use std::fmt::{self, Display};
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{de, ser};
|
||||
|
||||
use crate::bipack_source::BipackError;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
pub type Result<T> = std::result::Result<T, BipackError>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Message(String),
|
||||
BadFormat(String),
|
||||
Eof,
|
||||
ExtraBytes,
|
||||
BadEncoding,
|
||||
NotSupported,
|
||||
NotImplemented,
|
||||
NotPossible
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Error::Message(msg) => formatter.write_str(msg),
|
||||
_ => write!(formatter, "BiPack error: {:?}", self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl ser::Error for Error {
|
||||
impl ser::Error for BipackError {
|
||||
fn custom<T: Display>(msg: T) -> Self {
|
||||
Error::Message(msg.to_string())
|
||||
BipackError::Message(msg.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl de::Error for Error {
|
||||
impl de::Error for BipackError {
|
||||
fn custom<T: Display>(msg: T) -> Self {
|
||||
Error::Message(msg.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BipackError> for Error {
|
||||
fn from(value: BipackError) -> Self {
|
||||
match &value {
|
||||
BipackError::NoDataError => Error::Eof,
|
||||
BipackError::BadEncoding(_) => Error::BadEncoding,
|
||||
// other => Error::Message(format!("BiPack error: {}", value))
|
||||
}
|
||||
BipackError::Message(msg.to_string())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user