Skip to content

Commit cc94c4d

Browse files
authored
Change the Option types' is_some and is_none methods to take self by reference (#16)
1 parent 1b6c4f2 commit cc94c4d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

deranged/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,14 @@ macro_rules! impl_ranged {
10011001

10021002
/// Returns `true` if the value is the niche value.
10031003
#[inline(always)]
1004-
pub const fn is_none(self) -> bool {
1004+
pub const fn is_none(&self) -> bool {
10051005
<$type<MIN, MAX> as $crate::traits::RangeIsValid>::ASSERT;
10061006
self.get().is_none()
10071007
}
10081008

10091009
/// Returns `true` if the value is not the niche value.
10101010
#[inline(always)]
1011-
pub const fn is_some(self) -> bool {
1011+
pub const fn is_some(&self) -> bool {
10121012
<$type<MIN, MAX> as $crate::traits::RangeIsValid>::ASSERT;
10131013
self.get().is_some()
10141014
}

deranged/src/tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ macro_rules! tests {
147147
assert!($opt::<5, 10>::None.is_none());
148148
)*}
149149

150+
#[test]
151+
fn is_some_by_ref() {$(
152+
let value = $opt::<5, 10>::Some($t::<5, 10>::MAX);
153+
assert!($opt::is_some(&value));
154+
)*}
155+
156+
#[test]
157+
fn is_none_by_ref() {$(
158+
let value = $opt::<5, 10>::None;
159+
assert!($opt::is_none(&value));
160+
)*}
161+
150162
#[test]
151163
fn default() {$(
152164
assert_eq!($opt::<5, 10>::default(), $opt::<5, 10>::None);

0 commit comments

Comments
 (0)