use core::fmt;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HarmonicDegree(pub usize);
impl HarmonicDegree {
#[inline]
pub const fn new(value: usize) -> Self {
Self(value)
}
#[inline]
pub const fn get(self) -> usize {
self.0
}
}
impl Default for HarmonicDegree {
#[inline]
fn default() -> Self {
Self(0)
}
}
impl fmt::Debug for HarmonicDegree {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "HarmonicDegree({})", self.0)
}
}
impl fmt::Display for HarmonicDegree {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<usize> for HarmonicDegree {
#[inline]
fn from(value: usize) -> Self {
Self(value)
}
}
impl From<HarmonicDegree> for usize {
#[inline]
fn from(value: HarmonicDegree) -> Self {
value.0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_is_zero() {
assert_eq!(HarmonicDegree::default(), HarmonicDegree::new(0));
assert_eq!(HarmonicDegree::default().get(), 0);
}
#[test]
fn ordering_is_natural() {
assert!(HarmonicDegree(3) < HarmonicDegree(8));
assert!(HarmonicDegree(70) > HarmonicDegree(8));
assert_eq!(HarmonicDegree(8), HarmonicDegree(8));
}
#[test]
fn round_trip_through_usize() {
let d = HarmonicDegree::from(8usize);
let back: usize = d.into();
assert_eq!(back, 8);
}
#[test]
fn debug_and_display_show_inner_value() {
let d = HarmonicDegree(70);
assert_eq!(format!("{d}"), "70");
assert_eq!(format!("{d:?}"), "HarmonicDegree(70)");
}
}