summaryrefslogtreecommitdiff
path: root/src/codec/error.rs
blob: 43da48877abd274523d6fe0fd009707335746476 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use thiserror::Error;

#[derive(Debug, Error)]
pub enum CodecError {
    #[error("io error: {0}")]
    IoError(#[from] std::io::Error),
    #[error("WrongSize expected : {expected} ; got : {got}")]
    WrongSize { expected: usize, got: usize },
    #[error("{0}")]
    Custom(String),
}

pub type Result<T> = core::result::Result<T, CodecError>;

impl From<&str> for CodecError {
    fn from(value: &str) -> Self {
        Self::Custom(value.to_string())
    }
}

impl From<String> for CodecError {
    fn from(value: String) -> Self {
        Self::Custom(value)
    }
}