nestle_core/
error.rs

1use thiserror::Error;
2
3/// This value is too wide to fit into the remaining bits.
4#[derive(Debug, Error)]
5#[error("{type_name} requires {width} bits but only {remaining} bits remain at offset {offset}")]
6pub struct ValueTooWide {
7    pub type_name: &'static str,
8    pub offset: u8,
9    pub width: u8,
10    pub remaining: u8,
11}
12
13/// It's impossible for encoding to fail if the `Nestle` trait has been
14/// implemented exclusively through the derive macros.
15#[derive(Debug, Error)]
16pub enum EncodeError {
17    #[error("{0}")]
18    ValueTooWide(#[from] ValueTooWide),
19}
20
21/// Failure modes decoding an integer id.
22#[derive(Debug, Error)]
23pub enum DecodeError {
24    #[error("{0}")]
25    ValueTooWide(#[from] ValueTooWide),
26    #[error("Type {typ} has no value {disc}")]
27    NotFound { typ: &'static str, disc: i64 },
28    #[error("Successfully parsed {typ} but trailing bits were not zero: {value}")]
29    TrailingBits { typ: &'static str, value: i64 },
30}