serde_binary/
error.rs

1use std::fmt;
2use thiserror::Error;
3
4/// Errors thrown by the serde integration.
5#[derive(Debug, Error)]
6pub enum Error {
7    /// Custom error message.
8    #[error("{0}")]
9    Custom(String),
10
11    /// Error generated when a sequence has too many items.
12    #[error("sequence has too many items, limit is 2^32")]
13    TooManyItems,
14
15    /// Error generated by the binary reader or writer.
16    #[error(transparent)]
17    Binary(#[from] binary_stream::BinaryError),
18
19    /// Error generated converting to slices.
20    #[error(transparent)]
21    TryFromSlice(#[from] std::array::TryFromSliceError),
22
23    /// Generic error type for user space errors.
24    #[error(transparent)]
25    Boxed(#[from] Box<dyn std::error::Error + Send + Sync>),
26}
27
28impl serde::ser::Error for Error {
29    #[cold]
30    fn custom<T: fmt::Display>(msg: T) -> Self {
31        Self::Custom(msg.to_string())
32    }
33}
34
35impl serde::de::Error for Error {
36    #[cold]
37    fn custom<T: fmt::Display>(msg: T) -> Self {
38        Self::Custom(msg.to_string())
39    }
40}