Expose the range parser (#1993)

This commit is contained in:
Rushmore Mushambi 2023-05-15 17:46:20 +02:00 committed by GitHub
parent 10f29fbb26
commit c02d176646
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<Id>,
}
impl FromStr for Range {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(s)
}
}
impl TryFrom<&str> for Range {
type Error = ();
fn try_from(v: &str) -> Result<Self, Self::Error> {
match range(v) {
Ok((_, v)) => Ok(v),
_ => Err(()),
}
}
}
impl Range {
/// Process this type returning a computed simple Value
pub(crate) async fn compute(