diff --git a/src/lib.rs b/src/lib.rs index aee3ea9..70996a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -957,14 +957,14 @@ macro_rules! impl_ranged { /// Returns `true` if the value is the niche value. #[inline(always)] - pub const fn is_none(self) -> bool { + pub const fn is_none(&self) -> bool { <$type as $crate::traits::RangeIsValid>::ASSERT; self.get().is_none() } /// Returns `true` if the value is not the niche value. #[inline(always)] - pub const fn is_some(self) -> bool { + pub const fn is_some(&self) -> bool { <$type as $crate::traits::RangeIsValid>::ASSERT; self.get().is_some() } diff --git a/src/tests.rs b/src/tests.rs index e9a6ff7..2345ad4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,11 +1,11 @@ use std::hash::Hash; use crate::{ - IntErrorKind, OptionRangedI128, OptionRangedI16, OptionRangedI32, OptionRangedI64, - OptionRangedI8, OptionRangedIsize, OptionRangedU128, OptionRangedU16, OptionRangedU32, - OptionRangedU64, OptionRangedU8, OptionRangedUsize, ParseIntError, RangedI128, RangedI16, - RangedI32, RangedI64, RangedI8, RangedIsize, RangedU128, RangedU16, RangedU32, RangedU64, - RangedU8, RangedUsize, TryFromIntError, + IntErrorKind, OptionRangedI8, OptionRangedI16, OptionRangedI32, OptionRangedI64, + OptionRangedI128, OptionRangedIsize, OptionRangedU8, OptionRangedU16, OptionRangedU32, + OptionRangedU64, OptionRangedU128, OptionRangedUsize, ParseIntError, RangedI8, RangedI16, + RangedI32, RangedI64, RangedI128, RangedIsize, RangedU8, RangedU16, RangedU32, RangedU64, + RangedU128, RangedUsize, TryFromIntError, }; macro_rules! if_signed { @@ -63,12 +63,9 @@ fn errors() { "number would be zero for non-zero type" ); assert_eq!( - format!( - "{:?}", - ParseIntError { - kind: IntErrorKind::Empty - } - ), + format!("{:?}", ParseIntError { + kind: IntErrorKind::Empty + }), "ParseIntError { kind: Empty }" ); assert_eq!( @@ -147,6 +144,18 @@ macro_rules! tests { assert!($opt::<5, 10>::None.is_none()); )*} + #[test] + fn is_some_by_ref() {$( + let value = $opt::<5, 10>::Some($t::<5, 10>::MAX); + assert!($opt::is_some(&value)); + )*} + + #[test] + fn is_none_by_ref() {$( + let value = $opt::<5, 10>::None; + assert!($opt::is_none(&value)); + )*} + #[test] fn default() {$( assert_eq!($opt::<5, 10>::default(), $opt::<5, 10>::None); diff --git a/src/traits.rs b/src/traits.rs index d1b69ac..279142e 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,6 +1,6 @@ use crate::{ - RangedI128, RangedI16, RangedI32, RangedI64, RangedI8, RangedIsize, RangedU128, RangedU16, - RangedU32, RangedU64, RangedU8, RangedUsize, + RangedI8, RangedI16, RangedI32, RangedI64, RangedI128, RangedIsize, RangedU8, RangedU16, + RangedU32, RangedU64, RangedU128, RangedUsize, }; macro_rules! declare_traits {