diff --git a/src/lib.rs b/src/lib.rs index 2727058..49e314e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,6 +153,15 @@ macro_rules! nonmax { pub const fn get(&self) -> $primitive { self.0.get() ^ $primitive::MAX } + + /// Gets non-max with the value zero (0) + pub const ZERO: $nonmax = unsafe { Self::new_unchecked(0) }; + + /// Gets non-max with the value one (1) + pub const ONE: $nonmax = unsafe { Self::new_unchecked(1) }; + + /// Gets non-max with maximum possible value (which is maximum of the underlying primitive minus one) + pub const MAX: $nonmax = unsafe { Self::new_unchecked($primitive::MAX - 1) }; } impl Default for $nonmax { @@ -274,15 +283,25 @@ macro_rules! nonmax { #[test] fn cmp() { - let zero = NonMaxU8::new(0).unwrap(); - let one = NonMaxU8::new(1).unwrap(); - let two = NonMaxU8::new(2).unwrap(); + let zero = $nonmax::new(0).unwrap(); + let one = $nonmax::new(1).unwrap(); + let two = $nonmax::new(2).unwrap(); assert!(zero < one); assert!(one < two); assert!(two > one); assert!(one > zero); } + #[test] + fn constants() { + let zero = $nonmax::ZERO; + let one = $nonmax::ONE; + let max = $nonmax::MAX; + assert_eq!(zero.get(), 0); + assert_eq!(one.get(), 1); + assert_eq!(max.get(), $primitive::MAX - 1); + } + #[test] #[cfg(feature = "std")] // to_string fn parse() {