From 612ecc4ebc8e53e1c57d0841a0920e94237c927a Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 10 Oct 2020 13:41:55 +0800 Subject: [PATCH] Move StaticVec definition to lib.rs. --- src/api.rs | 2 +- src/engine.rs | 3 +-- src/fn_args.rs | 2 +- src/fn_call.rs | 3 +-- src/fn_native.rs | 2 +- src/lib.rs | 33 +++++++++++++++++---------------- src/module/mod.rs | 4 ++-- src/optimize.rs | 3 +-- src/packages/mod.rs | 2 +- src/packages/string_more.rs | 2 +- src/parser.rs | 4 ++-- src/syntax.rs | 2 +- src/token.rs | 2 +- src/utils.rs | 7 ------- 14 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/api.rs b/src/api.rs index aec4a39a..53a78e95 100644 --- a/src/api.rs +++ b/src/api.rs @@ -28,7 +28,7 @@ use crate::{ use crate::fn_register::{RegisterFn, RegisterResultFn}; #[cfg(not(feature = "no_function"))] -use crate::{fn_args::FuncArgs, fn_call::ensure_no_data_race, utils::StaticVec}; +use crate::{fn_args::FuncArgs, fn_call::ensure_no_data_race, StaticVec}; #[cfg(not(feature = "no_optimize"))] use crate::optimize::optimize_into_ast; diff --git a/src/engine.rs b/src/engine.rs index eee41038..42c023e9 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1,7 +1,6 @@ //! Main module defining the script evaluation `Engine`. use crate::any::{map_std_type_name, Dynamic, Union}; -use crate::calc_fn_hash; use crate::fn_call::run_builtin_op_assignment; use crate::fn_native::{Callback, FnPtr}; use crate::module::{Module, ModuleRef}; @@ -13,7 +12,7 @@ use crate::result::EvalAltResult; use crate::scope::{EntryType as ScopeEntryType, Scope}; use crate::syntax::{CustomSyntax, EvalContext}; use crate::token::Position; -use crate::utils::StaticVec; +use crate::{calc_fn_hash, StaticVec}; #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] use crate::any::Variant; diff --git a/src/fn_args.rs b/src/fn_args.rs index 600e8d94..07405c0f 100644 --- a/src/fn_args.rs +++ b/src/fn_args.rs @@ -3,7 +3,7 @@ #![allow(non_snake_case)] use crate::any::{Dynamic, Variant}; -use crate::utils::StaticVec; +use crate::StaticVec; /// Trait that represents arguments to a function call. /// Any data type that can be converted into a `Vec` can be used diff --git a/src/fn_call.rs b/src/fn_call.rs index 358713f0..7dc97319 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -1,7 +1,6 @@ //! Implement function-calling mechanism for `Engine`. use crate::any::Dynamic; -use crate::calc_fn_hash; use crate::engine::{ search_imports, search_namespace, search_scope_only, Engine, Imports, State, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_FN, @@ -16,7 +15,7 @@ use crate::result::EvalAltResult; use crate::scope::Scope; use crate::stdlib::ops::Deref; use crate::token::Position; -use crate::utils::StaticVec; +use crate::{calc_fn_hash, StaticVec}; #[cfg(not(feature = "no_function"))] use crate::{ diff --git a/src/fn_native.rs b/src/fn_native.rs index ef413d20..01c1f17b 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -10,7 +10,7 @@ use crate::token::{is_valid_identifier, Position}; use crate::utils::ImmutableString; #[cfg(not(feature = "no_function"))] -use crate::{calc_fn_hash, module::FuncReturn, utils::StaticVec}; +use crate::{calc_fn_hash, module::FuncReturn, StaticVec}; use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, string::String, vec::Vec}; diff --git a/src/lib.rs b/src/lib.rs index f61af46c..2cb73e0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ //! # Rhai - embedded scripting for Rust //! -//! Rhai is a tiny, simple and very fast embedded scripting language for Rust +//! Rhai is a tiny, simple and fast embedded scripting language for Rust //! that gives you a safe and easy way to add scripting to your applications. //! It provides a familiar syntax based on JavaScript and Rust and a simple Rust interface. //! Here is a quick example. @@ -74,7 +74,7 @@ pub mod plugin; mod result; mod scope; #[cfg(feature = "serde")] -mod serde; +mod serde_impl; mod settings; mod stdlib; mod syntax; @@ -124,21 +124,14 @@ pub use module::ModuleResolver; /// Module containing all built-in _module resolvers_ available to Rhai. #[cfg(not(feature = "no_module"))] -pub mod module_resolvers { - pub use crate::module::resolvers::*; -} +pub use crate::module::resolvers as module_resolvers; -/// _[SERDE]_ Serialization support for [`serde`](https://crates.io/crates/serde). +/// _[SERDE]_ Serialization and deserialization support for [`serde`](https://crates.io/crates/serde). /// Exported under the `serde` feature. #[cfg(feature = "serde")] -pub mod ser { - pub use crate::serde::ser::to_dynamic; -} -/// _[SERDE]_ Deserialization support for [`serde`](https://crates.io/crates/serde). -/// Exported under the `serde` feature. -#[cfg(feature = "serde")] -pub mod de { - pub use crate::serde::de::from_dynamic; +pub mod serde { + pub use super::serde_impl::de::from_dynamic; + pub use super::serde_impl::ser::to_dynamic; } #[cfg(not(feature = "no_optimize"))] @@ -166,6 +159,14 @@ pub use engine::{Imports, Limits, State as EvalState}; #[deprecated(note = "this type is volatile and may change")] pub use module::ModuleRef; +/// _[INTERNALS]_ Alias to [`smallvec::SmallVec<[T; 4]>`](https://crates.io/crates/smallvec), +/// which is a specialized `Vec` backed by a small, fixed-size array when there are <= 4 items stored. +/// Exported under the `internals` feature only. +#[cfg(not(feature = "internals"))] +type StaticVec = smallvec::SmallVec<[T; 4]>; + +/// _[INTERNALS]_ Alias to [`smallvec::SmallVec<[T; 4]>`](https://crates.io/crates/smallvec), +/// which is a specialized `Vec` backed by a small, fixed-size array when there are <= 4 items stored. +/// Exported under the `internals` feature only. #[cfg(feature = "internals")] -#[deprecated(note = "this type is volatile and may change")] -pub use utils::StaticVec; +pub type StaticVec = smallvec::SmallVec<[T; 4]>; diff --git a/src/module/mod.rs b/src/module/mod.rs index d9c1a356..3056d19b 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -1,14 +1,14 @@ //! Module defining external-loaded modules for Rhai. use crate::any::{Dynamic, Variant}; -use crate::calc_fn_hash; use crate::engine::Engine; use crate::fn_native::{CallableFunction, FnCallArgs, IteratorFn, SendSync}; use crate::fn_register::by_value as cast_arg; use crate::parser::FnAccess; use crate::result::EvalAltResult; use crate::token::{Position, Token}; -use crate::utils::{ImmutableString, StaticVec, StraightHasherBuilder}; +use crate::utils::{ImmutableString, StraightHasherBuilder}; +use crate::{calc_fn_hash, StaticVec}; #[cfg(not(feature = "no_function"))] use crate::{fn_native::Shared, parser::ScriptFnDef}; diff --git a/src/optimize.rs b/src/optimize.rs index b1134215..a314cdac 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -1,7 +1,6 @@ //! Module implementing the AST optimizer. use crate::any::Dynamic; -use crate::calc_fn_hash; use crate::engine::{ Engine, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_IS_DEF_FN, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_TYPE_OF, @@ -11,7 +10,7 @@ use crate::module::Module; use crate::parser::{map_dynamic_to_expr, Expr, ScriptFnDef, Stmt, AST}; use crate::scope::{Entry as ScopeEntry, Scope}; use crate::token::{is_valid_identifier, Position}; -use crate::utils::StaticVec; +use crate::{calc_fn_hash, StaticVec}; #[cfg(not(feature = "no_function"))] use crate::parser::ReturnType; diff --git a/src/packages/mod.rs b/src/packages/mod.rs index 1c6dc3a9..d7c7d023 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -2,7 +2,7 @@ use crate::fn_native::{CallableFunction, IteratorFn, Shared}; use crate::module::Module; -use crate::utils::StaticVec; +use crate::StaticVec; use crate::stdlib::any::TypeId; diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 0f667285..e89e03f8 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -6,7 +6,7 @@ use crate::engine::Engine; use crate::fn_native::FnPtr; use crate::parser::{ImmutableString, INT}; use crate::plugin::*; -use crate::utils::StaticVec; +use crate::StaticVec; #[cfg(not(feature = "unchecked"))] use crate::{result::EvalAltResult, token::Position}; diff --git a/src/parser.rs b/src/parser.rs index 04699a3f..4e932fe9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,7 +1,6 @@ //! Main module defining the lexer and parser. use crate::any::{Dynamic, Union}; -use crate::calc_fn_hash; use crate::engine::{Engine, KEYWORD_THIS, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT}; use crate::error::{LexError, ParseError, ParseErrorType}; use crate::fn_native::{FnPtr, Shared}; @@ -10,7 +9,8 @@ use crate::optimize::{optimize_into_ast, OptimizationLevel}; use crate::scope::{EntryType as ScopeEntryType, Scope}; use crate::syntax::FnCustomSyntaxEval; use crate::token::{is_keyword_function, is_valid_identifier, Position, Token, TokenStream}; -use crate::utils::{StaticVec, StraightHasherBuilder}; +use crate::utils::StraightHasherBuilder; +use crate::{calc_fn_hash, StaticVec}; #[cfg(not(feature = "no_index"))] use crate::engine::Array; diff --git a/src/syntax.rs b/src/syntax.rs index 085aa0d4..35c6b00e 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -9,7 +9,7 @@ use crate::parser::Expr; use crate::result::EvalAltResult; use crate::scope::Scope; use crate::token::{is_valid_identifier, Position, Token}; -use crate::utils::StaticVec; +use crate::StaticVec; use crate::stdlib::{ boxed::Box, diff --git a/src/token.rs b/src/token.rs index 5e6dfe57..40555217 100644 --- a/src/token.rs +++ b/src/token.rs @@ -10,7 +10,7 @@ use crate::engine::KEYWORD_IS_SHARED; use crate::error::LexError; use crate::parser::INT; -use crate::utils::StaticVec; +use crate::StaticVec; #[cfg(not(feature = "no_float"))] use crate::parser::FLOAT; diff --git a/src/utils.rs b/src/utils.rs index 417e9547..06a7ef53 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -21,8 +21,6 @@ use crate::stdlib::collections::hash_map::DefaultHasher; #[cfg(feature = "no_std")] use ahash::AHasher; -use smallvec::SmallVec; - /// A hasher that only takes one single `u64` and returns it as a hash key. /// /// # Panics @@ -93,11 +91,6 @@ pub fn calc_fn_hash<'a>( s.finish() } -/// _[INTERNALS]_ Alias to [`smallvec::SmallVec<[T; 4]>`](https://crates.io/crates/smallvec), -/// which is a specialized `Vec` backed by a small, fixed-size array when there are <= 4 items stored. -/// Exported under the `internals` feature only. -pub type StaticVec = SmallVec<[T; 4]>; - /// The system immutable string type. /// /// An `ImmutableString` wraps an `Rc` (or `Arc` under the `sync` feature)