Skip to content

Commit

Permalink
Derive Copy trait
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Ramla-I authored Jan 10, 2023
1 parent 581ee24 commit 7998070
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use core::iter::Step;
use core::ops::{RangeBounds, Bound, Bound::Included};

#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct RangeInclusive<Idx: Clone + PartialOrd> {
pub(crate) start: Idx,
pub(crate) end: Idx
Expand Down Expand Up @@ -36,7 +36,7 @@ impl<Idx: Clone + PartialOrd> RangeInclusive<Idx> {
}

pub fn is_empty(&self) -> bool {
self.end < self.start
!(self.start <= self.end)
}

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

0 comments on commit 7998070

Please sign in to comment.