Skip to content

Commit c64484f

Browse files
committed
implement RangeBounds for TextRange
1 parent 4832de6 commit c64484f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/lib.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,6 @@ pub struct TextRange {
220220
end: TextUnit,
221221
}
222222

223-
impl TextRange {
224-
#[inline(always)]
225-
pub fn checked_sub(self, other: TextUnit) -> Option<TextRange> {
226-
let res = TextRange::offset_len(self.start().checked_sub(other)?, self.len());
227-
Some(res)
228-
}
229-
}
230-
231223
impl fmt::Debug for TextRange {
232224
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
233225
<Self as fmt::Display>::fmt(self, f)
@@ -307,6 +299,25 @@ impl TextRange {
307299
pub fn contains_inclusive(&self, offset: TextUnit) -> bool {
308300
self.start() <= offset && offset <= self.end()
309301
}
302+
303+
#[inline(always)]
304+
pub fn checked_sub(self, other: TextUnit) -> Option<TextRange> {
305+
let res = TextRange::offset_len(
306+
self.start().checked_sub(other)?,
307+
self.len()
308+
);
309+
Some(res)
310+
}
311+
}
312+
313+
impl ops::RangeBounds<TextUnit> for TextRange {
314+
fn start_bound(&self) -> ops::Bound<&TextUnit> {
315+
ops::Bound::Included(&self.start)
316+
}
317+
318+
fn end_bound(&self) -> ops::Bound<&TextUnit> {
319+
ops::Bound::Excluded(&self.end)
320+
}
310321
}
311322

312323
impl ops::Index<TextRange> for str {

0 commit comments

Comments
 (0)