solid_core/
error.rs

1#[cfg(feature = "derive")]
2use serde::{
3    de,
4    ser,
5};
6use std::{
7    fmt,
8    string::FromUtf8Error,
9};
10
11/// Simple wrapper around `std::result::Result`
12pub type Result<T, E = Error> = std::result::Result<T, E>;
13
14/// Crate level error type
15#[derive(Debug, thiserror::Error)]
16pub enum Error {
17    Message(String),
18    Eof,
19    TrailingCharacters,
20    TryIntoSliceError(#[from] std::array::TryFromSliceError),
21    Utf8Error(#[from] std::str::Utf8Error),
22    FromUtf8Error(#[from] FromUtf8Error),
23    FromHexError(#[from] hex::FromHexError),
24}
25
26#[cfg(feature = "derive")]
27impl ser::Error for Error {
28    fn custom<T: fmt::Display>(msg: T) -> Self {
29        Error::Message(msg.to_string())
30    }
31}
32
33#[cfg(feature = "derive")]
34impl de::Error for Error {
35    fn custom<T: fmt::Display>(msg: T) -> Self {
36        Error::Message(msg.to_string())
37    }
38}
39
40impl fmt::Display for Error {
41    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
42        formatter.write_str(&self.to_string())
43    }
44}