From c02d176646259e6a200b12656a73c351246c1bfe Mon Sep 17 00:00:00 2001 From: Rushmore Mushambi Date: Mon, 15 May 2023 17:46:20 +0200 Subject: [PATCH] Expose the range parser (#1993) --- lib/src/sql/range.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/src/sql/range.rs b/lib/src/sql/range.rs index 3d8bf9b7..befa9ee6 100644 --- a/lib/src/sql/range.rs +++ b/lib/src/sql/range.rs @@ -17,6 +17,7 @@ use serde::{Deserialize, Serialize}; use std::cmp::Ordering; use std::fmt; use std::ops::Bound; +use std::str::FromStr; pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Range"; @@ -29,6 +30,23 @@ pub struct Range { pub end: Bound, } +impl FromStr for Range { + type Err = (); + fn from_str(s: &str) -> Result { + Self::try_from(s) + } +} + +impl TryFrom<&str> for Range { + type Error = (); + fn try_from(v: &str) -> Result { + match range(v) { + Ok((_, v)) => Ok(v), + _ => Err(()), + } + } +} + impl Range { /// Process this type returning a computed simple Value pub(crate) async fn compute(