mod test;
use std::fmt::{self, Debug, Display, Formatter};
#[repr(transparent)]
#[derive(Copy)]
#[derive_const(
Clone,
Eq,
Ord,
PartialEq,
PartialOrd,
)]
pub struct SampleDepth(Inner);
impl SampleDepth {
pub const MIN: Self = Self(Inner::U8);
pub const MAX: Self = Self(Inner::U64);
#[inline]
#[must_use]
pub const fn new(value: u32) -> Option<Self> {
match value {
1 => Some(Self(Inner::U8)),
2 => Some(Self(Inner::U16)),
3 => Some(Self(Inner::U24)),
4 => Some(Self(Inner::U32)),
5 => Some(Self(Inner::U40)),
6 => Some(Self(Inner::U48)),
7 => Some(Self(Inner::U56)),
8 => Some(Self(Inner::U64)),
_ => None,
}
}
#[inline]
#[must_use]
pub const fn get(self) -> u32 {
self.as_u8().into()
}
#[inline(always)]
#[must_use]
pub const fn as_u8(self) -> u8 {
self.0 as u8
}
#[inline]
#[must_use]
pub const fn as_u64(self) -> u64 {
self.get().into()
}
#[inline]
#[must_use]
pub const fn as_usize(self) -> usize {
self.as_u8().into()
}
}
impl Debug for SampleDepth {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Debug::fmt(&self.get(), f)
}
}
const impl Default for SampleDepth {
#[inline(always)]
fn default() -> Self {
const { Self::new(3).unwrap() }
}
}
impl Display for SampleDepth {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}B", self.get())
}
}
#[repr(u8)]
#[derive(Copy, Debug)]
#[derive_const(
Clone,
Eq,
Ord,
PartialEq,
PartialOrd,
)]
enum Inner {
U8 = 1,
U16 = 2,
U24 = 3,
U32 = 4,
U40 = 5,
U48 = 6,
U56 = 7,
U64 = 8,
}