Move StaticVec definition to lib.rs.

This commit is contained in:
Stephen Chung 2020-10-10 13:41:55 +08:00
parent 95c4ac4180
commit 612ecc4ebc
14 changed files with 31 additions and 40 deletions

View File

@ -28,7 +28,7 @@ use crate::{
use crate::fn_register::{RegisterFn, RegisterResultFn}; use crate::fn_register::{RegisterFn, RegisterResultFn};
#[cfg(not(feature = "no_function"))] #[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"))] #[cfg(not(feature = "no_optimize"))]
use crate::optimize::optimize_into_ast; use crate::optimize::optimize_into_ast;

View File

@ -1,7 +1,6 @@
//! Main module defining the script evaluation `Engine`. //! Main module defining the script evaluation `Engine`.
use crate::any::{map_std_type_name, Dynamic, Union}; 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_call::run_builtin_op_assignment;
use crate::fn_native::{Callback, FnPtr}; use crate::fn_native::{Callback, FnPtr};
use crate::module::{Module, ModuleRef}; use crate::module::{Module, ModuleRef};
@ -13,7 +12,7 @@ use crate::result::EvalAltResult;
use crate::scope::{EntryType as ScopeEntryType, Scope}; use crate::scope::{EntryType as ScopeEntryType, Scope};
use crate::syntax::{CustomSyntax, EvalContext}; use crate::syntax::{CustomSyntax, EvalContext};
use crate::token::Position; use crate::token::Position;
use crate::utils::StaticVec; use crate::{calc_fn_hash, StaticVec};
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
use crate::any::Variant; use crate::any::Variant;

View File

@ -3,7 +3,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::any::{Dynamic, Variant}; use crate::any::{Dynamic, Variant};
use crate::utils::StaticVec; use crate::StaticVec;
/// Trait that represents arguments to a function call. /// Trait that represents arguments to a function call.
/// Any data type that can be converted into a `Vec<Dynamic>` can be used /// Any data type that can be converted into a `Vec<Dynamic>` can be used

View File

@ -1,7 +1,6 @@
//! Implement function-calling mechanism for `Engine`. //! Implement function-calling mechanism for `Engine`.
use crate::any::Dynamic; use crate::any::Dynamic;
use crate::calc_fn_hash;
use crate::engine::{ use crate::engine::{
search_imports, search_namespace, search_scope_only, Engine, Imports, State, KEYWORD_DEBUG, 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, 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::scope::Scope;
use crate::stdlib::ops::Deref; use crate::stdlib::ops::Deref;
use crate::token::Position; use crate::token::Position;
use crate::utils::StaticVec; use crate::{calc_fn_hash, StaticVec};
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
use crate::{ use crate::{

View File

@ -10,7 +10,7 @@ use crate::token::{is_valid_identifier, Position};
use crate::utils::ImmutableString; use crate::utils::ImmutableString;
#[cfg(not(feature = "no_function"))] #[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}; use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, string::String, vec::Vec};

View File

@ -1,6 +1,6 @@
//! # Rhai - embedded scripting for Rust //! # 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. //! 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. //! It provides a familiar syntax based on JavaScript and Rust and a simple Rust interface.
//! Here is a quick example. //! Here is a quick example.
@ -74,7 +74,7 @@ pub mod plugin;
mod result; mod result;
mod scope; mod scope;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
mod serde; mod serde_impl;
mod settings; mod settings;
mod stdlib; mod stdlib;
mod syntax; mod syntax;
@ -124,21 +124,14 @@ pub use module::ModuleResolver;
/// Module containing all built-in _module resolvers_ available to Rhai. /// Module containing all built-in _module resolvers_ available to Rhai.
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
pub mod module_resolvers { pub use crate::module::resolvers as module_resolvers;
pub use crate::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. /// Exported under the `serde` feature.
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
pub mod ser { pub mod serde {
pub use crate::serde::ser::to_dynamic; pub use super::serde_impl::de::from_dynamic;
} pub use super::serde_impl::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;
} }
#[cfg(not(feature = "no_optimize"))] #[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")] #[deprecated(note = "this type is volatile and may change")]
pub use module::ModuleRef; 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<T> = 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")] #[cfg(feature = "internals")]
#[deprecated(note = "this type is volatile and may change")] pub type StaticVec<T> = smallvec::SmallVec<[T; 4]>;
pub use utils::StaticVec;

View File

@ -1,14 +1,14 @@
//! Module defining external-loaded modules for Rhai. //! Module defining external-loaded modules for Rhai.
use crate::any::{Dynamic, Variant}; use crate::any::{Dynamic, Variant};
use crate::calc_fn_hash;
use crate::engine::Engine; use crate::engine::Engine;
use crate::fn_native::{CallableFunction, FnCallArgs, IteratorFn, SendSync}; use crate::fn_native::{CallableFunction, FnCallArgs, IteratorFn, SendSync};
use crate::fn_register::by_value as cast_arg; use crate::fn_register::by_value as cast_arg;
use crate::parser::FnAccess; use crate::parser::FnAccess;
use crate::result::EvalAltResult; use crate::result::EvalAltResult;
use crate::token::{Position, Token}; 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"))] #[cfg(not(feature = "no_function"))]
use crate::{fn_native::Shared, parser::ScriptFnDef}; use crate::{fn_native::Shared, parser::ScriptFnDef};

View File

@ -1,7 +1,6 @@
//! Module implementing the AST optimizer. //! Module implementing the AST optimizer.
use crate::any::Dynamic; use crate::any::Dynamic;
use crate::calc_fn_hash;
use crate::engine::{ use crate::engine::{
Engine, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_IS_DEF_FN, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, Engine, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_IS_DEF_FN, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT,
KEYWORD_TYPE_OF, KEYWORD_TYPE_OF,
@ -11,7 +10,7 @@ use crate::module::Module;
use crate::parser::{map_dynamic_to_expr, Expr, ScriptFnDef, Stmt, AST}; use crate::parser::{map_dynamic_to_expr, Expr, ScriptFnDef, Stmt, AST};
use crate::scope::{Entry as ScopeEntry, Scope}; use crate::scope::{Entry as ScopeEntry, Scope};
use crate::token::{is_valid_identifier, Position}; use crate::token::{is_valid_identifier, Position};
use crate::utils::StaticVec; use crate::{calc_fn_hash, StaticVec};
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
use crate::parser::ReturnType; use crate::parser::ReturnType;

View File

@ -2,7 +2,7 @@
use crate::fn_native::{CallableFunction, IteratorFn, Shared}; use crate::fn_native::{CallableFunction, IteratorFn, Shared};
use crate::module::Module; use crate::module::Module;
use crate::utils::StaticVec; use crate::StaticVec;
use crate::stdlib::any::TypeId; use crate::stdlib::any::TypeId;

View File

@ -6,7 +6,7 @@ use crate::engine::Engine;
use crate::fn_native::FnPtr; use crate::fn_native::FnPtr;
use crate::parser::{ImmutableString, INT}; use crate::parser::{ImmutableString, INT};
use crate::plugin::*; use crate::plugin::*;
use crate::utils::StaticVec; use crate::StaticVec;
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
use crate::{result::EvalAltResult, token::Position}; use crate::{result::EvalAltResult, token::Position};

View File

@ -1,7 +1,6 @@
//! Main module defining the lexer and parser. //! Main module defining the lexer and parser.
use crate::any::{Dynamic, Union}; use crate::any::{Dynamic, Union};
use crate::calc_fn_hash;
use crate::engine::{Engine, KEYWORD_THIS, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT}; use crate::engine::{Engine, KEYWORD_THIS, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT};
use crate::error::{LexError, ParseError, ParseErrorType}; use crate::error::{LexError, ParseError, ParseErrorType};
use crate::fn_native::{FnPtr, Shared}; 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::scope::{EntryType as ScopeEntryType, Scope};
use crate::syntax::FnCustomSyntaxEval; use crate::syntax::FnCustomSyntaxEval;
use crate::token::{is_keyword_function, is_valid_identifier, Position, Token, TokenStream}; 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"))] #[cfg(not(feature = "no_index"))]
use crate::engine::Array; use crate::engine::Array;

View File

@ -9,7 +9,7 @@ use crate::parser::Expr;
use crate::result::EvalAltResult; use crate::result::EvalAltResult;
use crate::scope::Scope; use crate::scope::Scope;
use crate::token::{is_valid_identifier, Position, Token}; use crate::token::{is_valid_identifier, Position, Token};
use crate::utils::StaticVec; use crate::StaticVec;
use crate::stdlib::{ use crate::stdlib::{
boxed::Box, boxed::Box,

View File

@ -10,7 +10,7 @@ use crate::engine::KEYWORD_IS_SHARED;
use crate::error::LexError; use crate::error::LexError;
use crate::parser::INT; use crate::parser::INT;
use crate::utils::StaticVec; use crate::StaticVec;
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
use crate::parser::FLOAT; use crate::parser::FLOAT;

View File

@ -21,8 +21,6 @@ use crate::stdlib::collections::hash_map::DefaultHasher;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use ahash::AHasher; use ahash::AHasher;
use smallvec::SmallVec;
/// A hasher that only takes one single `u64` and returns it as a hash key. /// A hasher that only takes one single `u64` and returns it as a hash key.
/// ///
/// # Panics /// # Panics
@ -93,11 +91,6 @@ pub fn calc_fn_hash<'a>(
s.finish() 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<T> = SmallVec<[T; 4]>;
/// The system immutable string type. /// The system immutable string type.
/// ///
/// An `ImmutableString` wraps an `Rc<String>` (or `Arc<String>` under the `sync` feature) /// An `ImmutableString` wraps an `Rc<String>` (or `Arc<String>` under the `sync` feature)