Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/range.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use std::{
convert::{TryFrom, TryInto},
num::TryFromIntError,
};

use cmp::Ordering;

use {
Expand Down Expand Up @@ -392,6 +397,17 @@ where
}
}

impl TryFrom<Range<usize>> for TextRange {
type Error = TryFromIntError;
#[inline]
fn try_from(r: Range<usize>) -> Result<Self, TryFromIntError> {
let start = r.start.try_into()?;
let end = r.end.try_into()?;
assert!(start <= end);
Ok(Self::new(start, end))
}
}

macro_rules! ops {
(impl $Op:ident for TextRange by fn $f:ident = $op:tt) => {
impl $Op<&TextSize> for TextRange {
Expand Down