#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Lod(u8);
impl From<Lod> for u8 {
#[inline]
fn from(id: Lod) -> u8 {
id.0
}
}
impl From<u8> for Lod {
#[inline]
fn from(raw: u8) -> Self {
Self(raw)
}
}
impl std::fmt::Display for Lod {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.lod())
}
}
impl Lod {
#[must_use]
#[inline(always)]
pub const fn new(lod: u8) -> Self {
Self(lod)
}
#[must_use]
#[inline(always)]
pub const fn lod(&self) -> u8 {
self.0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
let lod = Lod::new(5);
assert_eq!(lod.lod(), 5);
}
#[test]
fn test_display() {
let lod = Lod::new(7);
assert_eq!(format!("{lod}"), "7");
}
#[test]
fn test_roundtrip() {
let val: u8 = 8;
let lod = Lod::new(val);
let back: u8 = lod.into();
assert_eq!(val, back);
}
#[test]
fn test_zero_lod() {
let lod = Lod::new(0);
assert_eq!(lod.lod(), 0);
}
#[test]
fn test_max_lod() {
let lod = Lod::new(u8::MAX);
assert_eq!(lod.lod(), 255);
}
}