From 480ae964b7386170103467ab73275cc5d667c76a Mon Sep 17 00:00:00 2001 From: AndyJado <101876416+AndyJado@users.noreply.github.com> Date: Sat, 25 Mar 2023 20:57:27 +0800 Subject: [PATCH] impl try_from Range for textRange --- src/range.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/range.rs b/src/range.rs index 4a98dee..0eaebca 100644 --- a/src/range.rs +++ b/src/range.rs @@ -1,3 +1,8 @@ +use std::{ + convert::{TryFrom, TryInto}, + num::TryFromIntError, +}; + use cmp::Ordering; use { @@ -392,6 +397,14 @@ where } } +impl TryFrom> for TextRange { + type Error = TryFromIntError; + #[inline] + fn try_from(r: Range) -> Result { + Ok(Self::new(r.start.try_into()?, r.end.try_into()?)) + } +} + macro_rules! ops { (impl $Op:ident for TextRange by fn $f:ident = $op:tt) => { impl $Op<&TextSize> for TextRange {