Skip to content

Commit 480ae96

Browse files
committed
impl try_from Range<usize> for textRange
1 parent e4d0f2b commit 480ae96

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/range.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
use std::{
2+
convert::{TryFrom, TryInto},
3+
num::TryFromIntError,
4+
};
5+
16
use cmp::Ordering;
27

38
use {
@@ -392,6 +397,14 @@ where
392397
}
393398
}
394399

400+
impl TryFrom<Range<usize>> for TextRange {
401+
type Error = TryFromIntError;
402+
#[inline]
403+
fn try_from(r: Range<usize>) -> Result<Self, TryFromIntError> {
404+
Ok(Self::new(r.start.try_into()?, r.end.try_into()?))
405+
}
406+
}
407+
395408
macro_rules! ops {
396409
(impl $Op:ident for TextRange by fn $f:ident = $op:tt) => {
397410
impl $Op<&TextSize> for TextRange {

0 commit comments

Comments
 (0)