Skip to content

Commit

Permalink
impl try_from Range<usize> for textRange
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyJado committed Mar 25, 2023
1 parent e4d0f2b commit 28d49f8
Showing 1 changed file with 16 additions and 0 deletions.
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

0 comments on commit 28d49f8

Please sign in to comment.