From 0ab86ac6237ef0f5a6ea5e7b44ca6d02c92043a2 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 29 Nov 2021 10:58:46 +0800 Subject: [PATCH] Move AST::new() and AST::new_with_source() to internals. --- CHANGELOG.md | 5 +-- src/ast.rs | 75 ++++++++++++++++++++++++++++++++----------- src/serde/metadata.rs | 2 +- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52567abf..3d901fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +15,12 @@ Enhancements * Added `into_array` and `into_typed_array` for `Dynamic`. * Added `FnPtr::call` to simplify calling a function pointer. -Deprecated API's ----------------- +Deprecated and Gated API's +-------------------------- * `NativeCallContext::new` is deprecated because it is simpler to call a function pointer via `FnPtr::call`. * `AST::merge_filtered` and `AST::combine_filtered` are no longer exported under `no_function`. +* `AST::new` and `AST::new_with_source` are moved under `internals`. Version 1.2.1 diff --git a/src/ast.rs b/src/ast.rs index 0d50f6ec..688bb3b2 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -196,7 +196,26 @@ impl Default for AST { impl AST { /// Create a new [`AST`]. - #[inline] + #[cfg(not(feature = "internals"))] + #[inline(always)] + #[must_use] + pub(crate) fn new( + statements: impl IntoIterator, + #[cfg(not(feature = "no_function"))] functions: impl Into>, + ) -> Self { + Self { + source: None, + body: StmtBlock::new(statements, Position::NONE), + #[cfg(not(feature = "no_function"))] + functions: functions.into(), + #[cfg(not(feature = "no_module"))] + resolver: None, + } + } + /// _(internals)_ Create a new [`AST`]. + /// Exported under the `internals` feature only. + #[cfg(feature = "internals")] + #[inline(always)] #[must_use] pub fn new( statements: impl IntoIterator, @@ -211,6 +230,41 @@ impl AST { resolver: None, } } + /// Create a new [`AST`] with a source name. + #[cfg(not(feature = "internals"))] + #[inline(always)] + #[must_use] + pub(crate) fn new_with_source( + statements: impl IntoIterator, + #[cfg(not(feature = "no_function"))] functions: impl Into>, + source: impl Into, + ) -> Self { + let mut ast = Self::new( + statements, + #[cfg(not(feature = "no_function"))] + functions, + ); + ast.set_source(source); + ast + } + /// _(internals)_ Create a new [`AST`] with a source name. + /// Exported under the `internals` feature only. + #[cfg(feature = "internals")] + #[inline(always)] + #[must_use] + pub fn new_with_source( + statements: impl IntoIterator, + #[cfg(not(feature = "no_function"))] functions: impl Into>, + source: impl Into, + ) -> Self { + let mut ast = Self::new( + statements, + #[cfg(not(feature = "no_function"))] + functions, + ); + ast.set_source(source); + ast + } /// Create an empty [`AST`]. #[inline] #[must_use] @@ -224,23 +278,6 @@ impl AST { resolver: None, } } - /// Create a new [`AST`] with a source name. - #[inline(always)] - #[must_use] - pub fn new_with_source( - statements: impl IntoIterator, - #[cfg(not(feature = "no_function"))] functions: impl Into>, - source: impl Into, - ) -> Self { - Self { - source: Some(source.into()), - body: StmtBlock::new(statements, Position::NONE), - #[cfg(not(feature = "no_function"))] - functions: functions.into(), - #[cfg(not(feature = "no_module"))] - resolver: None, - } - } /// Get the source, if any. #[inline(always)] #[must_use] @@ -286,7 +323,7 @@ impl AST { &self.body.0 } /// Get a mutable reference to the statements. - #[cfg(not(feature = "no_optimize"))] + #[allow(dead_code)] #[inline(always)] #[must_use] pub(crate) fn statements_mut(&mut self) -> &mut StaticVec { diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs index 83be1d86..ef67b4e2 100644 --- a/src/serde/metadata.rs +++ b/src/serde/metadata.rs @@ -272,7 +272,7 @@ impl Engine { } /// Generate a list of all functions in JSON format. - /// Available only under the `metadata` feature. + /// Exported under the `metadata` feature only. /// /// Functions from the following sources are included: /// 1) Functions registered into the global namespace