tiny_varint/
error.rs

1/// Error type for varint encoding/decoding operations
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum Error {
4    /// Output buffer is too small to hold the encoded data
5    BufferTooSmall {
6        /// Number of bytes needed
7        needed: usize,
8        /// Actual buffer size
9        actual: usize,
10    },
11    /// Overflow error encountered during decoding
12    Overflow,
13    /// Input data is insufficient during decoding
14    InputTooShort,
15    /// Invalid varint encoding encountered during decoding
16    InvalidEncoding,
17}
18
19// Helper methods for the Error error type
20impl Error {
21    /// Get the required buffer size
22    pub fn needed(&self) -> Option<usize> {
23        match self {
24            Error::BufferTooSmall { needed, .. } => Some(*needed),
25            _ => None,
26        }
27    }
28    
29    /// Get the actual buffer size
30    pub fn actual(&self) -> Option<usize> {
31        match self {
32            Error::BufferTooSmall { actual, .. } => Some(*actual),
33            _ => None,
34        }
35    }
36}