slicur 0.3.0

A library for reading network IO bytes buffer
Documentation
//! Error types.

use core::fmt;
use core::num::NonZeroUsize;

#[derive(Debug, Clone, Copy)]
/// Error type.
pub enum Error {
    /// Insufficient data.
    InsufficientData {
        /// Number of bytes missing to complete the operation.
        missing: NonZeroUsize,
    },

    /// Rare error: overflow
    Overflow,
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InsufficientData {
                missing: remaining_bytes,
            } => write!(
                f,
                "Insufficient data, need {remaining_bytes} bytes to complete the operation.",
            ),
            Self::Overflow => write!(f, "Overflow occurred during length calculation."),
        }
    }
}