rawbin 1.0.0

Minimal, pure-Rust bincode-like serializer/deserializer used by pacm.
Documentation
use std::fmt;

#[derive(Debug)]
pub enum DecodeError {
    UnexpectedEof,
    InvalidUtf8(std::str::Utf8Error),
    Message(String),
}

impl fmt::Display for DecodeError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            DecodeError::UnexpectedEof => write!(f, "unexpected eof"),
            DecodeError::InvalidUtf8(e) => write!(f, "invalid utf-8: {}", e),
            DecodeError::Message(s) => write!(f, "{}", s),
        }
    }
}

impl std::error::Error for DecodeError {}

pub type Result<T> = std::result::Result<T, DecodeError>;

impl serde::de::Error for DecodeError {
    fn custom<T: std::fmt::Display>(msg: T) -> Self {
        DecodeError::Message(msg.to_string())
    }
}