safer_bytes/
error.rs

1//! Errors
2
3/// Errors that can occur when deserialising objects from a buffer
4#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone, Copy)]
5#[non_exhaustive]
6pub enum Error {
7    /// Tried to read something, but not enough bytes left in the buffer
8    #[error(transparent)]
9    Truncated(#[from] Truncated),
10
11    /// Called Reader::should_be_exhausted(), but found bytes anyway.
12    #[error(transparent)]
13    ExtraneousBytes(#[from] ExtraneousBytes),
14
15    /// An attempt to parse an object failed for some reason related to its
16    /// contents.
17    #[error("deserialisation error: {0}")]
18    Deserialization(&'static str),
19}
20
21/// Tried to read something, but not enough bytes left in the buffer
22#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone, Copy)]
23#[error("object truncated (or not fully present)")]
24pub struct Truncated;
25
26#[rustfmt::skip]
27/// Called [`SafeBuf::should_be_exhausted`](crate::SafeBuf::should_be_exhausted), but found bytes remaining
28#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone, Copy)]
29#[error("extra bytes at end of object")]
30pub struct ExtraneousBytes;