Skip to content

Commit 28d49f8

Browse files
committed
impl try_from Range<usize> for textRange
1 parent e4d0f2b commit 28d49f8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/range.rs

+16
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,17 @@ 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+
let start = r.start.try_into()?;
405+
let end = r.end.try_into()?;
406+
assert!(start <= end);
407+
Ok(Self::new(start, end))
408+
}
409+
}
410+
395411
macro_rules! ops {
396412
(impl $Op:ident for TextRange by fn $f:ident = $op:tt) => {
397413
impl $Op<&TextSize> for TextRange {

0 commit comments

Comments
 (0)