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
//! Errors

/// Errors that can occur when deserialising objects from a buffer
#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone, Copy)]
#[non_exhaustive]
pub enum Error {
    /// Tried to read something, but not enough bytes left in the buffer
    #[error(transparent)]
    Truncated(#[from] Truncated),

    /// Called Reader::should_be_exhausted(), but found bytes anyway.
    #[error(transparent)]
    ExtraneousBytes(#[from] ExtraneousBytes),

    /// An attempt to parse an object failed for some reason related to its
    /// contents.
    #[error("deserialisation error: {0}")]
    Deserialization(&'static str),
}

/// Tried to read something, but not enough bytes left in the buffer
#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone, Copy)]
#[error("object truncated (or not fully present)")]
pub struct Truncated;

#[rustfmt::skip]
/// Called [`SafeBuf::should_be_exhausted`](crate::SafeBuf::should_be_exhausted), but found bytes remaining
#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone, Copy)]
#[error("extra bytes at end of object")]
pub struct ExtraneousBytes;