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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use cid::Error as CidError;
use serde_cbor::error::Error as CborError;
use std::fmt;
use std::io;
use thiserror::Error;
#[derive(Debug, PartialEq, Error)]
#[error("Serialization error for {protocol} protocol: {description}")]
pub struct Error {
pub description: String,
pub protocol: CodecProtocol,
}
impl From<CborError> for Error {
fn from(err: CborError) -> Error {
Self {
description: err.to_string(),
protocol: CodecProtocol::Cbor,
}
}
}
impl From<CidError> for Error {
fn from(err: CidError) -> Self {
Self {
description: err.to_string(),
protocol: CodecProtocol::Cbor,
}
}
}
impl From<Error> for io::Error {
fn from(err: Error) -> Self {
Self::new(io::ErrorKind::Other, err)
}
}
#[derive(Debug, PartialEq)]
pub enum CodecProtocol {
Cbor,
}
impl fmt::Display for CodecProtocol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
CodecProtocol::Cbor => write!(f, "Cbor"),
}
}
}