common: add more methods to SectionRange
This commit is contained in:
parent
90d2e1636a
commit
61b478ca0e
1 changed files with 34 additions and 0 deletions
|
@ -81,6 +81,40 @@ impl<T: Ord + Copy> SectionRange<T> {
|
|||
};
|
||||
intersection == *other
|
||||
}
|
||||
|
||||
/// Returns the start of the range.
|
||||
#[must_use]
|
||||
pub fn start(&self) -> &T {
|
||||
&self.start
|
||||
}
|
||||
|
||||
/// Returns the end of the range.
|
||||
#[must_use]
|
||||
pub fn end(&self) -> &T {
|
||||
&self.end
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Add<Output = T> + Clone> SectionRange<T> {
|
||||
/// Offsets both the start and end of the range by the given offset.
|
||||
#[must_use]
|
||||
pub fn offset_by(self, offset: T) -> SectionRange<T> {
|
||||
Self {
|
||||
start: self.start + offset.clone(),
|
||||
end: self.end + offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Sub<Output = T> + Clone> SectionRange<T> {
|
||||
/// Offsets both the start and end of the range by the given offset in the negative direction.
|
||||
#[must_use]
|
||||
pub fn offset_by_neg(self, offset: T) -> SectionRange<T> {
|
||||
Self {
|
||||
start: self.start - offset.clone(),
|
||||
end: self.end - offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ord + Copy + Sub<Output = L>, L: TryInto<usize>> SectionRange<T> {
|
||||
|
|
Loading…
Reference in a new issue