From 9c18025ccaa6424b0da593567017517ab18db463 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 21 Feb 2023 14:15:19 +0000 Subject: [PATCH] Use new SQL `Block` type for `` expressions --- lib/src/kvs/ds.rs | 2 +- lib/src/sql/future.rs | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/src/kvs/ds.rs b/lib/src/kvs/ds.rs index 7a2e9938..9f02a7de 100644 --- a/lib/src/kvs/ds.rs +++ b/lib/src/kvs/ds.rs @@ -322,7 +322,7 @@ impl Datastore { /// async fn main() -> Result<(), Error> { /// let ds = Datastore::new("memory").await?; /// let ses = Session::for_kv(); - /// let val = Value::Future(Box::new(Future(Value::True))); + /// let val = Value::Future(Box::new(Future::from(Value::True))); /// let res = ds.compute(val, &ses, None, false).await?; /// Ok(()) /// } diff --git a/lib/src/sql/future.rs b/lib/src/sql/future.rs index 13cf9c98..3f61e82d 100644 --- a/lib/src/sql/future.rs +++ b/lib/src/sql/future.rs @@ -2,16 +2,23 @@ use crate::ctx::Context; use crate::dbs::Options; use crate::dbs::Transaction; use crate::err::Error; +use crate::sql::block::{block, Block}; use crate::sql::comment::mightbespace; use crate::sql::error::IResult; -use crate::sql::value::{value, Value}; +use crate::sql::value::Value; use nom::bytes::complete::tag; use nom::character::complete::char; use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)] -pub struct Future(pub Value); +pub struct Future(pub Block); + +impl From for Future { + fn from(v: Value) -> Self { + Future(Block::from(v)) + } +} impl Future { pub(crate) async fn compute( @@ -33,7 +40,7 @@ impl Future { impl fmt::Display for Future { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, " {{ {} }}", self.0) + write!(f, " {}", self.0) } } @@ -42,11 +49,7 @@ pub fn future(i: &str) -> IResult<&str, Future> { let (i, _) = tag("future")(i)?; let (i, _) = char('>')(i)?; let (i, _) = mightbespace(i)?; - let (i, _) = char('{')(i)?; - let (i, _) = mightbespace(i)?; - let (i, v) = value(i)?; - let (i, _) = mightbespace(i)?; - let (i, _) = char('}')(i)?; + let (i, v) = block(i)?; Ok((i, Future(v))) } #[cfg(test)] @@ -63,6 +66,6 @@ mod tests { assert!(res.is_ok()); let out = res.unwrap().1; assert_eq!(" { 1.2345 + 5.4321 }", format!("{}", out)); - assert_eq!(out, Future(Value::from(Expression::parse("1.2345 + 5.4321")))); + assert_eq!(out, Future(Block::from(Value::from(Expression::parse("1.2345 + 5.4321"))))); } }