use core::sync::atomic::{AtomicU64, Ordering};
use s2n_quic_core::varint::VarInt;
#[derive(Clone, Copy, Debug)]
pub struct ExhaustionError;
#[derive(Debug, Default)]
pub struct Counter(AtomicU64);
impl Counter {
#[inline]
pub fn reset(&self) {
self.0.store(0, Ordering::Relaxed)
}
#[inline]
pub fn next(&self) -> Result<VarInt, ExhaustionError> {
let pn = self.0.fetch_add(1, Ordering::Relaxed);
VarInt::new(pn).map_err(|_| ExhaustionError)
}
}