From 61b478ca0ed520abb3b233e3a3f74593e961c946 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Tue, 5 Dec 2023 19:38:33 +0000 Subject: [PATCH] common: add more methods to SectionRange --- common/rust/src/section_range.rs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/common/rust/src/section_range.rs b/common/rust/src/section_range.rs index 56d7739..8e8a25b 100644 --- a/common/rust/src/section_range.rs +++ b/common/rust/src/section_range.rs @@ -81,6 +81,40 @@ impl SectionRange { }; 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 + Clone> SectionRange { + /// Offsets both the start and end of the range by the given offset. + #[must_use] + pub fn offset_by(self, offset: T) -> SectionRange { + Self { + start: self.start + offset.clone(), + end: self.end + offset, + } + } +} + +impl + Clone> SectionRange { + /// 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 { + Self { + start: self.start - offset.clone(), + end: self.end - offset, + } + } } impl, L: TryInto> SectionRange {