car_nostd/
error.rs

1use alloc::string::{String, ToString};
2
3pub enum Error {
4    Parsing(String),
5    InvalidFile(String),
6    Io(core2::io::Error),
7    Cbor(serde_ipld_dagcbor::error::CodecError),
8    LdReadTooLarge(usize),
9}
10
11impl core::fmt::Debug for Error {
12    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
13        match self {
14            Error::Parsing(s) => write!(f, "Parsing error: {}", s),
15            Error::InvalidFile(s) => write!(f, "Invalid file error: {}", s),
16            Error::Io(e) => write!(f, "Io error: {}", e),
17            Error::Cbor(e) => write!(f, "Cbor error: {}", e),
18            Error::LdReadTooLarge(s) => write!(f, "Ld read too large: {}", s),
19        }
20    }
21}
22
23impl From<core2::io::Error> for Error {
24    fn from(err: core2::io::Error) -> Error {
25        Error::Io(err)
26    }
27}
28
29impl From<cid::Error> for Error {
30    fn from(err: cid::Error) -> Error {
31        Error::Parsing(err.to_string())
32    }
33}
34
35impl From<cid::multihash::Error> for Error {
36    fn from(err: cid::multihash::Error) -> Error {
37        Error::Parsing(err.to_string())
38    }
39}