#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
pub enum CongestionControl {
Block = 0,
Drop = 1,
}
impl Default for CongestionControl {
fn default() -> Self {
Self::DEFAULT
}
}
impl CongestionControl {
pub const DEFAULT: Self = Self::Block;
pub(crate) const unsafe fn from_bool(v: bool) -> Self {
unsafe { core::mem::transmute(v) }
}
#[cfg(test)]
pub(crate) fn rand() -> Self {
use rand::Rng;
let mut rng = rand::rng();
if rng.random_bool(0.5) { Self::Drop } else { Self::Block }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_from_bool() {
let block = unsafe { CongestionControl::from_bool(false) };
assert_eq!(block, CongestionControl::Block);
let drop = unsafe { CongestionControl::from_bool(true) };
assert_eq!(drop, CongestionControl::Drop);
}
}