common: add more methods to SectionRange

This commit is contained in:
Xiretza 2023-12-05 19:38:33 +00:00
parent 90d2e1636a
commit 61b478ca0e

View file

@ -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> {