diff --git a/Cargo.toml b/Cargo.toml index 7882f7c..8270290 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "text-size" -version = "1.1.1" +version = "1.2.0" edition = "2018" authors = [ diff --git a/src/range.rs b/src/range.rs index 9b98164..6b463ac 100644 --- a/src/range.rs +++ b/src/range.rs @@ -1,3 +1,5 @@ +use std::convert::{TryFrom, TryInto}; + use cmp::Ordering; use { @@ -392,6 +394,20 @@ where } } +impl TryFrom> for TextRange +where + T: TryInto, +{ + type Error = >::Error; + #[inline] + fn try_from(value: Range) -> Result { + Ok(TextRange::new( + value.start.try_into()?, + value.end.try_into()?, + )) + } +} + macro_rules! ops { (impl $Op:ident for TextRange by fn $f:ident = $op:tt) => { impl $Op<&TextSize> for TextRange {