Skip to content

Commit 7998070

Browse files
authoredJan 10, 2023
Derive Copy trait
- We can now derive Copy trait because RangeInclusive no longer implements Iterator, just IntoIterator. Discussions on not deriving Copy made the argument that it doesn't remain clear when an iterator is mutating the range or not (Iterator and Copy should be mutually exclusive?) see issue: rust-lang/rfcs#2848 - also updated is_empty with the defn found in the std library.
1 parent 581ee24 commit 7998070

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use core::iter::Step;
55
use core::ops::{RangeBounds, Bound, Bound::Included};
66

7-
#[derive(Debug, Clone, PartialEq, Eq)]
7+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
88
pub struct RangeInclusive<Idx: Clone + PartialOrd> {
99
pub(crate) start: Idx,
1010
pub(crate) end: Idx
@@ -36,7 +36,7 @@ impl<Idx: Clone + PartialOrd> RangeInclusive<Idx> {
3636
}
3737

3838
pub fn is_empty(&self) -> bool {
39-
self.end < self.start
39+
!(self.start <= self.end)
4040
}
4141

4242
pub fn contains<U>(&self, item: &U) -> bool
@@ -82,4 +82,4 @@ impl<A: Step> Iterator for RangeInclusiveIterator<A> {
8282
Some(core::mem::replace(&mut self.offset, n))
8383
}
8484
}
85-
}
85+
}

0 commit comments

Comments
 (0)
Please sign in to comment.