From 7c93622b5788326cb5425f8895b9800b04c69aa6 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 14 Jul 2021 14:00:10 +0800 Subject: [PATCH] Handle more data types in Expr::from_dynamic. --- src/ast.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 01b41fe3..a7d882e9 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -221,7 +221,7 @@ impl AST { ) -> Self { Self { source: None, - body: StmtBlock::new(statements.into_iter().collect(), Position::NONE), + body: StmtBlock::new(statements, Position::NONE), functions: functions.into(), #[cfg(not(feature = "no_module"))] resolver: None, @@ -237,7 +237,7 @@ impl AST { ) -> Self { Self { source: Some(source.into()), - body: StmtBlock::new(statements.into_iter().collect(), Position::NONE), + body: StmtBlock::new(statements, Position::NONE), functions: functions.into(), #[cfg(not(feature = "no_module"))] resolver: None, @@ -889,7 +889,8 @@ pub struct StmtBlock(StaticVec, Position); impl StmtBlock { /// Create a new [`StmtBlock`]. #[must_use] - pub fn new(mut statements: StaticVec, pos: Position) -> Self { + pub fn new(statements: impl IntoIterator, pos: Position) -> Self { + let mut statements: StaticVec<_> = statements.into_iter().collect(); statements.shrink_to_fit(); Self(statements, pos) } @@ -1685,7 +1686,7 @@ impl FloatWrapper { /// Create a new [`FloatWrapper`]. #[inline(always)] #[must_use] - pub(crate) const fn const_new(value: FLOAT) -> Self { + pub const fn new_const(value: FLOAT) -> Self { Self(value) } } @@ -1910,9 +1911,18 @@ impl Expr { Union::Char(c, _, _) => Self::CharConstant(c, pos), Union::Int(i, _, _) => Self::IntegerConstant(i, pos), + #[cfg(feature = "decimal")] + Union::Decimal(value, _, _) => Self::DynamicConstant(Box::new((*value).into()), pos), + #[cfg(not(feature = "no_float"))] Union::Float(f, _, _) => Self::FloatConstant(f, pos), + #[cfg(not(feature = "no_index"))] + Union::Array(a, _, _) => Self::DynamicConstant(Box::new((*a).into()), pos), + + #[cfg(not(feature = "no_object"))] + Union::Map(m, _, _) => Self::DynamicConstant(Box::new((*m).into()), pos), + _ => Self::DynamicConstant(value.into(), pos), } }