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};
#[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;

View File

@ -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;

View File

@ -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<Dynamic>` can be used

View File

@ -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::{

View File

@ -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};

View File

@ -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<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")]
#[deprecated(note = "this type is volatile and may change")]
pub use utils::StaticVec;
pub type StaticVec<T> = smallvec::SmallVec<[T; 4]>;

View File

@ -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};

View File

@ -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;

View File

@ -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;

View File

@ -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};

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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<T> = SmallVec<[T; 4]>;
/// The system immutable string type.
///
/// An `ImmutableString` wraps an `Rc<String>` (or `Arc<String>` under the `sync` feature)