flux_limiter/
errors.rs

1// src/errors.rs
2
3// error handling for the flux limiter type
4
5// dependencies
6use std::error::Error;
7use std::fmt;
8
9use crate::clock::ClockError;
10
11/// Error type for FluxLimiter configuration issues.
12#[non_exhaustive]
13#[derive(Debug)]
14pub enum FluxLimiterError {
15    InvalidRate,            // for rate <= 0
16    InvalidBurst,           // for burst < 0
17    ClockError(ClockError), // error variant for issues with the system clock
18}
19
20// implement the Display trait for the FluxLimiterError type
21impl fmt::Display for FluxLimiterError {
22    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23        match self {
24            FluxLimiterError::InvalidRate => write!(f, "Rate must be positive"),
25            FluxLimiterError::InvalidBurst => write!(f, "Burst must be non-negative"),
26            FluxLimiterError::ClockError(_) => {
27                write!(f, "Clock error occurred")
28            }
29        }
30    }
31}
32
33// implement the Error trait for the RateLimiter type
34impl Error for FluxLimiterError {}