diff --git a/src/ast.rs b/src/ast.rs index 301e490f..180cf638 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,23 +1,7 @@ //! Module defining the AST (abstract syntax tree). -use crate::dynamic::{Dynamic, Union}; -use crate::fn_native::{FnPtr, Shared}; -use crate::module::{Module, NamespaceRef}; -use crate::syntax::FnCustomSyntaxEval; -use crate::token::{Position, Token, NO_POS}; -use crate::utils::{ImmutableString, StraightHasherBuilder}; -use crate::StaticVec; -use crate::INT; - -#[cfg(not(feature = "no_float"))] -use crate::FLOAT; - -#[cfg(not(feature = "no_index"))] -use crate::Array; - -#[cfg(not(feature = "no_object"))] -use crate::Map; - +use crate::dynamic::Union; +use crate::module::NamespaceRef; use crate::stdlib::{ borrow::Cow, boxed::Box, @@ -30,6 +14,19 @@ use crate::stdlib::{ vec, vec::Vec, }; +use crate::syntax::FnCustomSyntaxEval; +use crate::token::Token; +use crate::utils::StraightHasherBuilder; +use crate::{Dynamic, FnPtr, ImmutableString, Module, Position, Shared, StaticVec, INT, NO_POS}; + +#[cfg(not(feature = "no_float"))] +use crate::FLOAT; + +#[cfg(not(feature = "no_index"))] +use crate::Array; + +#[cfg(not(feature = "no_object"))] +use crate::Map; /// A type representing the access mode of a scripted function. #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] @@ -55,16 +52,16 @@ impl FnAccess { #[inline(always)] pub fn is_private(self) -> bool { match self { - Self::Public => false, Self::Private => true, + Self::Public => false, } } /// Is this access mode public? #[inline(always)] pub fn is_public(self) -> bool { match self { - Self::Public => true, Self::Private => false, + Self::Public => true, } } } diff --git a/src/dynamic.rs b/src/dynamic.rs index ae23098d..2a6a0220 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -1,19 +1,7 @@ //! Helper module which defines the `Any` trait to to allow dynamic value handling. -use crate::fn_native::{FnPtr, SendSync}; +use crate::fn_native::SendSync; use crate::r#unsafe::{unsafe_cast_box, unsafe_try_cast}; -use crate::utils::ImmutableString; -use crate::INT; - -#[cfg(not(feature = "no_float"))] -use crate::FLOAT; - -#[cfg(not(feature = "no_index"))] -use crate::Array; - -#[cfg(not(feature = "no_object"))] -use crate::Map; - use crate::stdlib::{ any::{type_name, Any, TypeId}, boxed::Box, @@ -23,6 +11,16 @@ use crate::stdlib::{ ops::{Deref, DerefMut}, string::{String, ToString}, }; +use crate::{FnPtr, ImmutableString, INT}; + +#[cfg(not(feature = "no_float"))] +use crate::FLOAT; + +#[cfg(not(feature = "no_index"))] +use crate::Array; + +#[cfg(not(feature = "no_object"))] +use crate::Map; #[cfg(not(feature = "no_std"))] #[cfg(not(target_arch = "wasm32"))] diff --git a/src/engine.rs b/src/engine.rs index aaf460a7..68fc4bfb 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1,20 +1,13 @@ //! Main module defining the script evaluation `Engine`. use crate::ast::{Expr, FnCallExpr, Ident, IdentX, ReturnType, Stmt}; -use crate::dynamic::{map_std_type_name, Dynamic, Union, Variant}; +use crate::dynamic::{map_std_type_name, Union, Variant}; use crate::fn_call::run_builtin_op_assignment; -use crate::fn_native::{CallableFunction, Callback, FnPtr, IteratorFn, OnVarCallback, Shared}; -use crate::module::{Module, NamespaceRef}; -use crate::optimize::OptimizationLevel; +use crate::fn_native::{CallableFunction, Callback, IteratorFn, OnVarCallback}; +use crate::module::NamespaceRef; use crate::packages::{Package, PackagesCollection, StandardPackage}; use crate::r#unsafe::unsafe_cast_var_name_to_lifetime; -use crate::result::EvalAltResult; -use crate::scope::{EntryType as ScopeEntryType, Scope}; -use crate::syntax::CustomSyntax; -use crate::token::{Position, NO_POS}; -use crate::utils::{get_hasher, ImmutableString}; -use crate::{calc_native_fn_hash, StaticVec}; - +use crate::scope::EntryType as ScopeEntryType; use crate::stdlib::{ any::{type_name, TypeId}, borrow::Cow, @@ -27,6 +20,12 @@ use crate::stdlib::{ ops::DerefMut, string::{String, ToString}, }; +use crate::syntax::CustomSyntax; +use crate::utils::get_hasher; +use crate::{ + calc_native_fn_hash, Dynamic, EvalAltResult, FnPtr, ImmutableString, Module, OptimizationLevel, + Position, Scope, Shared, StaticVec, NO_POS, +}; #[cfg(not(feature = "no_index"))] use crate::Array; diff --git a/src/engine_api.rs b/src/engine_api.rs index 9e16303f..9ac15a34 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -1,32 +1,25 @@ //! Module that defines the extern API of `Engine`. -use crate::ast::AST; -use crate::dynamic::{Dynamic, Variant}; -use crate::engine::{Engine, EvalContext, Imports}; -use crate::fn_native::{FnCallArgs, NativeCallContext, SendSync}; -use crate::optimize::OptimizationLevel; -use crate::parse_error::ParseError; -use crate::result::EvalAltResult; -use crate::scope::Scope; -use crate::token::NO_POS; -use crate::utils::get_hasher; - -#[cfg(not(feature = "no_index"))] -use crate::Array; - -#[cfg(not(feature = "no_object"))] -use crate::Map; - +use crate::dynamic::Variant; +use crate::engine::{EvalContext, Imports}; +use crate::fn_native::{FnCallArgs, SendSync}; use crate::stdlib::{ any::{type_name, TypeId}, boxed::Box, hash::{Hash, Hasher}, string::String, }; +use crate::utils::get_hasher; +use crate::{ + scope::Scope, Dynamic, Engine, EvalAltResult, NativeCallContext, OptimizationLevel, ParseError, + AST, NO_POS, +}; -#[cfg(not(feature = "no_std"))] -#[cfg(not(target_arch = "wasm32"))] -use crate::stdlib::{fs::File, io::prelude::*, path::PathBuf}; +#[cfg(not(feature = "no_index"))] +use crate::Array; + +#[cfg(not(feature = "no_object"))] +use crate::Map; /// Calculate a unique hash for a script. fn calc_hash_for_scripts<'a>(scripts: impl IntoIterator) -> u64 { @@ -204,15 +197,11 @@ impl Engine { /// ``` #[cfg(not(feature = "no_object"))] #[inline(always)] - pub fn register_get( + pub fn register_get( &mut self, name: &str, callback: impl Fn(&mut T) -> U + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - { + ) -> &mut Self { crate::RegisterFn::register_fn(self, &crate::engine::make_getter(name), callback) } /// Register a getter function for a member of a registered type with the `Engine`. @@ -304,15 +293,11 @@ impl Engine { /// ``` #[cfg(not(feature = "no_object"))] #[inline(always)] - pub fn register_set( + pub fn register_set( &mut self, name: &str, callback: impl Fn(&mut T, U) + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - { + ) -> &mut Self { crate::RegisterFn::register_fn(self, &crate::engine::make_setter(name), callback) } /// Register a setter function for a member of a registered type with the `Engine`. @@ -357,15 +342,11 @@ impl Engine { /// ``` #[cfg(not(feature = "no_object"))] #[inline(always)] - pub fn register_set_result( + pub fn register_set_result( &mut self, name: &str, callback: impl Fn(&mut T, U) -> Result<(), Box> + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - { + ) -> &mut Self { crate::RegisterResultFn::register_result_fn( self, &crate::engine::make_setter(name), @@ -412,16 +393,12 @@ impl Engine { /// ``` #[cfg(not(feature = "no_object"))] #[inline(always)] - pub fn register_get_set( + pub fn register_get_set( &mut self, name: &str, get_fn: impl Fn(&mut T) -> U + SendSync + 'static, set_fn: impl Fn(&mut T, U) + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - { + ) -> &mut Self { self.register_get(name, get_fn).register_set(name, set_fn) } /// Register an index getter for a custom type with the `Engine`. @@ -467,15 +444,10 @@ impl Engine { /// ``` #[cfg(not(feature = "no_index"))] #[inline(always)] - pub fn register_indexer_get( + pub fn register_indexer_get( &mut self, callback: impl Fn(&mut T, X) -> U + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - X: Variant + Clone, - { + ) -> &mut Self { if TypeId::of::() == TypeId::of::() { panic!("Cannot register indexer for arrays."); } @@ -538,14 +510,10 @@ impl Engine { /// ``` #[cfg(not(feature = "no_index"))] #[inline(always)] - pub fn register_indexer_get_result( + pub fn register_indexer_get_result( &mut self, callback: impl Fn(&mut T, X) -> Result> + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - X: Variant + Clone, - { + ) -> &mut Self { if TypeId::of::() == TypeId::of::() { panic!("Cannot register indexer for arrays."); } @@ -605,15 +573,10 @@ impl Engine { /// ``` #[cfg(not(feature = "no_index"))] #[inline(always)] - pub fn register_indexer_set( + pub fn register_indexer_set( &mut self, callback: impl Fn(&mut T, X, U) + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - X: Variant + Clone, - { + ) -> &mut Self { if TypeId::of::() == TypeId::of::() { panic!("Cannot register indexer for arrays."); } @@ -677,15 +640,14 @@ impl Engine { /// ``` #[cfg(not(feature = "no_index"))] #[inline(always)] - pub fn register_indexer_set_result( + pub fn register_indexer_set_result< + T: Variant + Clone, + X: Variant + Clone, + U: Variant + Clone, + >( &mut self, callback: impl Fn(&mut T, X, U) -> Result<(), Box> + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - X: Variant + Clone, - { + ) -> &mut Self { if TypeId::of::() == TypeId::of::() { panic!("Cannot register indexer for arrays."); } @@ -748,16 +710,11 @@ impl Engine { /// ``` #[cfg(not(feature = "no_index"))] #[inline(always)] - pub fn register_indexer_get_set( + pub fn register_indexer_get_set( &mut self, getter: impl Fn(&mut T, X) -> U + SendSync + 'static, setter: impl Fn(&mut T, X, U) -> () + SendSync + 'static, - ) -> &mut Self - where - T: Variant + Clone, - U: Variant + Clone, - X: Variant + Clone, - { + ) -> &mut Self { self.register_indexer_get(getter) .register_indexer_set(setter) } @@ -935,8 +892,10 @@ impl Engine { #[cfg(not(feature = "no_std"))] #[cfg(not(target_arch = "wasm32"))] #[inline] - fn read_file(path: PathBuf) -> Result> { - let mut f = File::open(path.clone()).map_err(|err| { + fn read_file(path: crate::stdlib::path::PathBuf) -> Result> { + use crate::stdlib::io::Read; + + let mut f = crate::stdlib::fs::File::open(path.clone()).map_err(|err| { EvalAltResult::ErrorSystem( format!("Cannot open script file '{}'", path.to_string_lossy()), err.into(), @@ -977,7 +936,10 @@ impl Engine { #[cfg(not(feature = "no_std"))] #[cfg(not(target_arch = "wasm32"))] #[inline(always)] - pub fn compile_file(&self, path: PathBuf) -> Result> { + pub fn compile_file( + &self, + path: crate::stdlib::path::PathBuf, + ) -> Result> { self.compile_file_with_scope(&Default::default(), path) } /// Compile a script file into an `AST` using own scope, which can be used later for evaluation. @@ -1017,7 +979,7 @@ impl Engine { pub fn compile_file_with_scope( &self, scope: &Scope, - path: PathBuf, + path: crate::stdlib::path::PathBuf, ) -> Result> { Self::read_file(path).and_then(|contents| Ok(self.compile_with_scope(scope, &contents)?)) } @@ -1201,7 +1163,10 @@ impl Engine { #[cfg(not(feature = "no_std"))] #[cfg(not(target_arch = "wasm32"))] #[inline(always)] - pub fn eval_file(&self, path: PathBuf) -> Result> { + pub fn eval_file( + &self, + path: crate::stdlib::path::PathBuf, + ) -> Result> { Self::read_file(path).and_then(|contents| self.eval::(&contents)) } /// Evaluate a script file with own scope. @@ -1229,7 +1194,7 @@ impl Engine { pub fn eval_file_with_scope( &self, scope: &mut Scope, - path: PathBuf, + path: crate::stdlib::path::PathBuf, ) -> Result> { Self::read_file(path).and_then(|contents| self.eval_with_scope::(scope, &contents)) } @@ -1428,7 +1393,10 @@ impl Engine { #[cfg(not(feature = "no_std"))] #[cfg(not(target_arch = "wasm32"))] #[inline(always)] - pub fn consume_file(&self, path: PathBuf) -> Result<(), Box> { + pub fn consume_file( + &self, + path: crate::stdlib::path::PathBuf, + ) -> Result<(), Box> { Self::read_file(path).and_then(|contents| self.consume(&contents)) } /// Evaluate a file with own scope, but throw away the result and only return error (if any). @@ -1439,7 +1407,7 @@ impl Engine { pub fn consume_file_with_scope( &self, scope: &mut Scope, - path: PathBuf, + path: crate::stdlib::path::PathBuf, ) -> Result<(), Box> { Self::read_file(path).and_then(|contents| self.consume_with_scope(scope, &contents)) } diff --git a/src/engine_settings.rs b/src/engine_settings.rs index 2c87a48a..09484087 100644 --- a/src/engine_settings.rs +++ b/src/engine_settings.rs @@ -1,10 +1,9 @@ //! Configuration settings for `Engine`. -use crate::engine::Engine; use crate::packages::PackageLibrary; -use crate::token::{is_valid_identifier, Token}; - use crate::stdlib::{format, string::String}; +use crate::token::{is_valid_identifier, Token}; +use crate::Engine; #[cfg(not(feature = "no_module"))] use crate::stdlib::boxed::Box; diff --git a/src/fn_args.rs b/src/fn_args.rs index db0f3cd4..d0c9de63 100644 --- a/src/fn_args.rs +++ b/src/fn_args.rs @@ -2,8 +2,8 @@ #![allow(non_snake_case)] -use crate::dynamic::{Dynamic, Variant}; -use crate::StaticVec; +use crate::dynamic::Variant; +use crate::{Dynamic, 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 b22f0554..d6b9c694 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -1,29 +1,14 @@ //! Implement function-calling mechanism for `Engine`. use crate::ast::{Expr, Stmt}; -use crate::dynamic::Dynamic; use crate::engine::{ - search_imports, Engine, Imports, State, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, + search_imports, Imports, State, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_FN, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_TYPE_OF, }; -use crate::fn_native::{FnCallArgs, FnPtr}; -use crate::module::{Module, NamespaceRef}; -use crate::optimize::OptimizationLevel; -use crate::parse_error::ParseErrorType; -use crate::result::EvalAltResult; -use crate::scope::{EntryType as ScopeEntryType, Scope}; -use crate::stdlib::ops::Deref; -use crate::token::NO_POS; -use crate::utils::ImmutableString; -use crate::{calc_native_fn_hash, calc_script_fn_hash, StaticVec, INT}; - -#[cfg(not(feature = "no_float"))] -use crate::FLOAT; - -#[cfg(not(feature = "no_object"))] -use crate::Map; - +use crate::fn_native::FnCallArgs; +use crate::module::NamespaceRef; +use crate::scope::EntryType as ScopeEntryType; use crate::stdlib::{ any::{type_name, TypeId}, boxed::Box, @@ -31,9 +16,20 @@ use crate::stdlib::{ format, iter::{empty, once}, mem, + ops::Deref, string::ToString, vec::Vec, }; +use crate::{ + calc_native_fn_hash, calc_script_fn_hash, Dynamic, Engine, EvalAltResult, FnPtr, + ImmutableString, Module, OptimizationLevel, ParseErrorType, Scope, StaticVec, INT, NO_POS, +}; + +#[cfg(not(feature = "no_float"))] +use crate::FLOAT; + +#[cfg(not(feature = "no_object"))] +use crate::Map; #[cfg(feature = "no_std")] #[cfg(not(feature = "no_float"))] diff --git a/src/fn_func.rs b/src/fn_func.rs index 888043c9..dc72f3b7 100644 --- a/src/fn_func.rs +++ b/src/fn_func.rs @@ -3,13 +3,8 @@ #![cfg(not(feature = "no_function"))] #![allow(non_snake_case)] -use crate::ast::AST; use crate::dynamic::Variant; -use crate::engine::Engine; -use crate::parse_error::ParseError; -use crate::result::EvalAltResult; -use crate::scope::Scope; - +use crate::{Engine, EvalAltResult, ParseError, Scope, AST}; use crate::stdlib::{boxed::Box, string::ToString}; /// Trait to create a Rust closure from a script. diff --git a/src/fn_native.rs b/src/fn_native.rs index 9bf6c3ab..c79b2e46 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -1,16 +1,14 @@ //! Module defining interfaces to native-Rust functions. -use crate::ast::{FnAccess, ScriptFnDef}; -use crate::dynamic::Dynamic; -use crate::engine::{Engine, EvalContext, Imports}; -use crate::module::Module; +use crate::ast::ScriptFnDef; +use crate::engine::Imports; use crate::plugin::PluginFunction; -use crate::result::EvalAltResult; -use crate::token::{is_valid_identifier, NO_POS}; -use crate::utils::ImmutableString; -use crate::{calc_script_fn_hash, StaticVec}; - use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, iter::empty, mem, string::String}; +use crate::token::is_valid_identifier; +use crate::{ + calc_script_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, FnAccess, ImmutableString, + Module, StaticVec, NO_POS, +}; #[cfg(not(feature = "sync"))] use crate::stdlib::rc::Rc; diff --git a/src/fn_register.rs b/src/fn_register.rs index f1e1f50e..07790a7f 100644 --- a/src/fn_register.rs +++ b/src/fn_register.rs @@ -2,15 +2,11 @@ #![allow(non_snake_case)] -use crate::ast::FnAccess; -use crate::dynamic::{Dynamic, DynamicWriteLock, Variant}; -use crate::engine::Engine; -use crate::fn_native::{CallableFunction, FnAny, FnCallArgs, NativeCallContext, SendSync}; +use crate::dynamic::{DynamicWriteLock, Variant}; +use crate::fn_native::{CallableFunction, FnAny, FnCallArgs, SendSync}; use crate::r#unsafe::unsafe_cast_box; -use crate::result::EvalAltResult; -use crate::utils::ImmutableString; - use crate::stdlib::{any::TypeId, boxed::Box, mem, string::String}; +use crate::{Dynamic, Engine, EvalAltResult, FnAccess, ImmutableString, NativeCallContext}; /// Trait to register custom functions with the `Engine`. pub trait RegisterFn { diff --git a/src/module/mod.rs b/src/module/mod.rs index b22da434..7c2fcc1d 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -1,24 +1,11 @@ //! Module defining external-loaded modules for Rhai. -use crate::ast::{FnAccess, IdentX}; -use crate::dynamic::{Dynamic, Variant}; +use crate::ast::IdentX; +use crate::dynamic::Variant; use crate::fn_native::{ - shared_make_mut, shared_take_or_clone, CallableFunction, FnCallArgs, IteratorFn, - NativeCallContext, SendSync, Shared, + shared_make_mut, shared_take_or_clone, CallableFunction, FnCallArgs, IteratorFn, SendSync, }; use crate::fn_register::by_value as cast_arg; -use crate::result::EvalAltResult; -use crate::token::{Token, NO_POS}; -use crate::utils::{ImmutableString, StraightHasherBuilder}; -use crate::StaticVec; - -#[cfg(not(feature = "no_index"))] -use crate::Array; - -#[cfg(not(feature = "no_index"))] -#[cfg(not(feature = "no_object"))] -use crate::Map; - use crate::stdlib::{ any::TypeId, boxed::Box, @@ -30,6 +17,18 @@ use crate::stdlib::{ string::{String, ToString}, vec::Vec, }; +use crate::token::Token; +use crate::utils::StraightHasherBuilder; +use crate::{ + Dynamic, EvalAltResult, FnAccess, ImmutableString, NativeCallContext, Shared, StaticVec, NO_POS, +}; + +#[cfg(not(feature = "no_index"))] +use crate::Array; + +#[cfg(not(feature = "no_index"))] +#[cfg(not(feature = "no_object"))] +use crate::Map; /// Data structure containing a single registered function. #[derive(Debug, Clone)] diff --git a/src/module/resolvers/collection.rs b/src/module/resolvers/collection.rs index f1f76e70..6b4f6d9a 100644 --- a/src/module/resolvers/collection.rs +++ b/src/module/resolvers/collection.rs @@ -1,10 +1,5 @@ -use crate::engine::Engine; -use crate::fn_native::Shared; -use crate::module::{Module, ModuleResolver}; -use crate::result::EvalAltResult; -use crate::token::Position; - use crate::stdlib::{boxed::Box, ops::AddAssign, vec::Vec}; +use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared}; /// Module resolution service that holds a collection of module resolves, /// to be searched in sequential order. diff --git a/src/module/resolvers/file.rs b/src/module/resolvers/file.rs index a76f26d0..4753937d 100644 --- a/src/module/resolvers/file.rs +++ b/src/module/resolvers/file.rs @@ -1,12 +1,7 @@ -use crate::engine::Engine; -use crate::fn_native::{Locked, Shared}; -use crate::module::{Module, ModuleResolver}; -use crate::result::EvalAltResult; -use crate::token::Position; - use crate::stdlib::{ boxed::Box, collections::HashMap, io::Error as IoError, path::PathBuf, string::String, }; +use crate::{Engine, EvalAltResult, Locked, Module, ModuleResolver, Position, Shared}; /// Module resolution service that loads module script files from the file system. /// diff --git a/src/module/resolvers/mod.rs b/src/module/resolvers/mod.rs index 62638130..d131a1d0 100644 --- a/src/module/resolvers/mod.rs +++ b/src/module/resolvers/mod.rs @@ -1,10 +1,6 @@ -use crate::engine::Engine; -use crate::fn_native::{SendSync, Shared}; -use crate::module::Module; -use crate::result::EvalAltResult; -use crate::token::Position; - +use crate::fn_native::SendSync; use crate::stdlib::boxed::Box; +use crate::{Engine, EvalAltResult, Module, Position, Shared}; mod collection; pub use collection::ModuleResolversCollection; diff --git a/src/module/resolvers/stat.rs b/src/module/resolvers/stat.rs index eabfd3e3..09deb1b7 100644 --- a/src/module/resolvers/stat.rs +++ b/src/module/resolvers/stat.rs @@ -1,10 +1,5 @@ -use crate::engine::Engine; -use crate::fn_native::Shared; -use crate::module::{Module, ModuleResolver}; -use crate::result::EvalAltResult; -use crate::token::Position; - use crate::stdlib::{boxed::Box, collections::HashMap, ops::AddAssign, string::String}; +use crate::{Engine, EvalAltResult, Module, ModuleResolver, Position, Shared}; /// Module resolution service that serves modules added into it. /// diff --git a/src/optimize.rs b/src/optimize.rs index ab95b2fe..01beb455 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -1,19 +1,12 @@ //! Module implementing the AST optimizer. -use crate::ast::{Expr, ScriptFnDef, Stmt, AST}; -use crate::dynamic::Dynamic; +use crate::ast::{Expr, ScriptFnDef, Stmt}; use crate::engine::{ - Engine, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_IS_DEF_FN, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, + KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_IS_DEF_FN, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_TYPE_OF, }; use crate::fn_call::run_builtin_binary_op; -use crate::module::Module; use crate::parser::map_dynamic_to_expr; -use crate::scope::Scope; -use crate::token::{is_valid_identifier, Position, NO_POS}; -use crate::utils::get_hasher; -use crate::{calc_native_fn_hash, StaticVec}; - use crate::stdlib::{ boxed::Box, hash::{Hash, Hasher}, @@ -23,6 +16,11 @@ use crate::stdlib::{ vec, vec::Vec, }; +use crate::token::is_valid_identifier; +use crate::utils::get_hasher; +use crate::{ + calc_native_fn_hash, Dynamic, Engine, Module, Position, Scope, StaticVec, AST, NO_POS, +}; /// Level of optimization performed. /// diff --git a/src/packages/arithmetic.rs b/src/packages/arithmetic.rs index c8398cea..5af2a2b8 100644 --- a/src/packages/arithmetic.rs +++ b/src/packages/arithmetic.rs @@ -1,10 +1,8 @@ #![allow(non_snake_case)] -use crate::def_package; use crate::plugin::*; -use crate::INT; - -use crate::{result::EvalAltResult, token::NO_POS}; +use crate::stdlib::{format, string::String}; +use crate::{def_package, EvalAltResult, INT, NO_POS}; #[cfg(not(feature = "no_float"))] use crate::FLOAT; @@ -13,8 +11,6 @@ use crate::FLOAT; #[cfg(not(feature = "no_float"))] use num_traits::float::Float; -use crate::stdlib::{format, string::String}; - #[inline(always)] pub fn make_err(msg: impl Into) -> Box { EvalAltResult::ErrorArithmetic(msg.into(), NO_POS).into() diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 69c3b7d6..8f493063 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -1,21 +1,17 @@ #![cfg(not(feature = "no_index"))] #![allow(non_snake_case)] -use crate::def_package; -use crate::dynamic::Dynamic; use crate::engine::{OP_EQUALS, TYPICAL_ARRAY_SIZE}; -use crate::fn_native::{FnPtr, NativeCallContext}; use crate::plugin::*; -use crate::result::EvalAltResult; -use crate::token::NO_POS; -use crate::utils::ImmutableString; -use crate::{Array, INT}; +use crate::stdlib::{any::TypeId, boxed::Box, cmp::max, cmp::Ordering, string::ToString}; +use crate::{ + def_package, Array, Dynamic, EvalAltResult, FnPtr, ImmutableString, NativeCallContext, INT, + NO_POS, +}; #[cfg(not(feature = "no_object"))] use crate::Map; -use crate::stdlib::{any::TypeId, boxed::Box, cmp::max, cmp::Ordering, string::ToString}; - pub type Unit = (); macro_rules! gen_array_functions { diff --git a/src/packages/eval.rs b/src/packages/eval.rs index 68012dc5..525b8f3a 100644 --- a/src/packages/eval.rs +++ b/src/packages/eval.rs @@ -1,8 +1,5 @@ -use crate::def_package; -use crate::dynamic::Dynamic; use crate::plugin::*; -use crate::result::EvalAltResult; -use crate::utils::ImmutableString; +use crate::{def_package, Dynamic, EvalAltResult, ImmutableString}; def_package!(crate:EvalPackage:"Disable 'eval'.", lib, { combine_with_exported_module!(lib, "eval", eval_override); diff --git a/src/packages/fn_basic.rs b/src/packages/fn_basic.rs index 64494290..630c58d9 100644 --- a/src/packages/fn_basic.rs +++ b/src/packages/fn_basic.rs @@ -1,6 +1,5 @@ -use crate::def_package; -use crate::fn_native::FnPtr; use crate::plugin::*; +use crate::{def_package, FnPtr}; def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, { combine_with_exported_module!(lib, "FnPtr", fn_ptr_functions); diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index a9ff0f10..c336707f 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -1,12 +1,9 @@ -use crate::def_package; use crate::dynamic::Variant; -use crate::result::EvalAltResult; -use crate::INT; - use crate::stdlib::{ boxed::Box, ops::{Add, Range}, }; +use crate::{def_package, EvalAltResult, INT}; fn get_range(from: T, to: T) -> Result, Box> { Ok(from..to) diff --git a/src/packages/map_basic.rs b/src/packages/map_basic.rs index d0102f12..22cdbe09 100644 --- a/src/packages/map_basic.rs +++ b/src/packages/map_basic.rs @@ -1,11 +1,8 @@ #![cfg(not(feature = "no_object"))] -use crate::def_package; -use crate::dynamic::Dynamic; use crate::engine::OP_EQUALS; use crate::plugin::*; -use crate::utils::ImmutableString; -use crate::{Map, INT}; +use crate::{def_package, Dynamic, ImmutableString, Map, INT}; #[cfg(not(feature = "no_index"))] use crate::Array; diff --git a/src/packages/math_basic.rs b/src/packages/math_basic.rs index 1dd00419..c186782a 100644 --- a/src/packages/math_basic.rs +++ b/src/packages/math_basic.rs @@ -1,9 +1,7 @@ #![allow(non_snake_case)] -use crate::def_package; use crate::plugin::*; -use crate::token::NO_POS; -use crate::INT; +use crate::{def_package, INT, NO_POS}; #[cfg(not(feature = "no_float"))] use crate::FLOAT; diff --git a/src/packages/mod.rs b/src/packages/mod.rs index df067fe1..4b0f8ecc 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -1,10 +1,8 @@ //! Module containing all built-in _packages_ available to Rhai, plus facilities to define custom packages. -use crate::fn_native::{CallableFunction, IteratorFn, Shared}; -use crate::module::Module; -use crate::StaticVec; - +use crate::fn_native::{CallableFunction, IteratorFn}; use crate::stdlib::any::TypeId; +use crate::{Module, Shared, StaticVec}; pub(crate) mod arithmetic; mod array_basic; diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index 99369195..2db28c7a 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -1,11 +1,13 @@ #![allow(non_snake_case)] -use crate::def_package; use crate::engine::{FN_TO_STRING, KEYWORD_DEBUG, KEYWORD_PRINT}; -use crate::fn_native::FnPtr; use crate::plugin::*; -use crate::utils::ImmutableString; -use crate::INT; +use crate::stdlib::{ + fmt::{Debug, Display}, + format, + string::ToString, +}; +use crate::{def_package, FnPtr, ImmutableString, INT}; #[cfg(not(feature = "no_index"))] use crate::Array; @@ -13,12 +15,6 @@ use crate::Array; #[cfg(not(feature = "no_object"))] use crate::Map; -use crate::stdlib::{ - fmt::{Debug, Display}, - format, - string::ToString, -}; - type Unit = (); macro_rules! gen_functions { diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 0e336f3e..661e00e8 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -1,16 +1,10 @@ #![allow(non_snake_case)] -use crate::def_package; -use crate::dynamic::Dynamic; -use crate::fn_native::FnPtr; use crate::plugin::*; -use crate::utils::ImmutableString; -use crate::StaticVec; -use crate::INT; - use crate::stdlib::{ any::TypeId, boxed::Box, format, mem, string::String, string::ToString, vec::Vec, }; +use crate::{def_package, Dynamic, FnPtr, ImmutableString, StaticVec, INT}; macro_rules! gen_concat_functions { ($root:ident => $($arg_type:ident),+ ) => { diff --git a/src/packages/time_basic.rs b/src/packages/time_basic.rs index e419905b..bcd50f55 100644 --- a/src/packages/time_basic.rs +++ b/src/packages/time_basic.rs @@ -1,18 +1,13 @@ #![cfg(not(feature = "no_std"))] use super::{arithmetic::make_err as make_arithmetic_err, math_basic::MAX_INT}; - -use crate::def_package; -use crate::dynamic::Dynamic; use crate::plugin::*; -use crate::result::EvalAltResult; -use crate::INT; +use crate::stdlib::boxed::Box; +use crate::{def_package, Dynamic, EvalAltResult, INT}; #[cfg(not(feature = "no_float"))] use crate::FLOAT; -use crate::stdlib::boxed::Box; - #[cfg(not(target_arch = "wasm32"))] use crate::stdlib::time::{Duration, Instant}; diff --git a/src/parse_error.rs b/src/parse_error.rs index f34a8f36..cd90d2d7 100644 --- a/src/parse_error.rs +++ b/src/parse_error.rs @@ -1,14 +1,12 @@ //! Module containing error definitions for the parsing process. -use crate::result::EvalAltResult; -use crate::token::{Position, NO_POS}; - use crate::stdlib::{ boxed::Box, error::Error, fmt, string::{String, ToString}, }; +use crate::{EvalAltResult, Position, NO_POS}; /// _[INTERNALS]_ Error encountered when tokenizing the script text. /// Exported under the `internals` feature only. diff --git a/src/parser.rs b/src/parser.rs index 136e798b..a4d26697 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,24 +1,13 @@ //! Main module defining the lexer and parser. use crate::ast::{ - BinaryExpr, CustomExpr, Expr, FnCallExpr, Ident, IdentX, ReturnType, ScriptFnDef, Stmt, AST, + BinaryExpr, CustomExpr, Expr, FnCallExpr, Ident, IdentX, ReturnType, ScriptFnDef, Stmt, }; -use crate::dynamic::{Dynamic, Union}; -use crate::engine::{Engine, KEYWORD_THIS, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT}; +use crate::dynamic::Union; +use crate::engine::{KEYWORD_THIS, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT}; use crate::module::NamespaceRef; -use crate::optimize::{optimize_into_ast, OptimizationLevel}; -use crate::parse_error::{LexError, ParseError, ParseErrorType}; -use crate::scope::{EntryType as ScopeEntryType, Scope}; -use crate::syntax::CustomSyntax; -use crate::token::{ - is_keyword_function, is_valid_identifier, Position, Token, TokenStream, NO_POS, -}; -use crate::utils::{get_hasher, ImmutableString, StraightHasherBuilder}; -use crate::{calc_script_fn_hash, StaticVec}; - -#[cfg(not(feature = "no_float"))] -use crate::FLOAT; - +use crate::optimize::optimize_into_ast; +use crate::scope::EntryType as ScopeEntryType; use crate::stdlib::{ borrow::Cow, boxed::Box, @@ -31,6 +20,16 @@ use crate::stdlib::{ vec, vec::Vec, }; +use crate::syntax::CustomSyntax; +use crate::token::{is_keyword_function, is_valid_identifier, Token, TokenStream}; +use crate::utils::{get_hasher, StraightHasherBuilder}; +use crate::{ + calc_script_fn_hash, Dynamic, Engine, ImmutableString, LexError, OptimizationLevel, ParseError, + ParseErrorType, Position, Scope, StaticVec, AST, NO_POS, +}; + +#[cfg(not(feature = "no_float"))] +use crate::FLOAT; type PERR = ParseErrorType; @@ -148,10 +147,10 @@ impl<'e> ParseState<'e> { } /// Get an interned string, creating one if it is not yet interned. - pub fn get_interned_string(&mut self, text: S) -> ImmutableString - where - S: AsRef + Into, - { + pub fn get_interned_string( + &mut self, + text: impl AsRef + Into, + ) -> ImmutableString { #[allow(clippy::map_entry)] if !self.strings.contains_key(text.as_ref()) { let value: ImmutableString = text.into(); diff --git a/src/plugin.rs b/src/plugin.rs index 7bce9b5c..2f45629f 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,15 +1,11 @@ //! Module defining macros for developing _plugins_. -pub use crate::ast::FnAccess; -pub use crate::dynamic::Dynamic; -pub use crate::engine::Engine; -pub use crate::fn_native::{CallableFunction, FnCallArgs, NativeCallContext}; -pub use crate::fn_register::{RegisterFn, RegisterResultFn}; -pub use crate::module::Module; -pub use crate::result::EvalAltResult; -pub use crate::utils::ImmutableString; - +pub use crate::fn_native::{CallableFunction, FnCallArgs}; pub use crate::stdlib::{any::TypeId, boxed::Box, format, mem, string::ToString, vec as new_vec}; +pub use crate::{ + Dynamic, Engine, EvalAltResult, FnAccess, ImmutableString, Module, NativeCallContext, + RegisterFn, RegisterResultFn, +}; #[cfg(not(features = "no_module"))] pub use rhai_codegen::*; diff --git a/src/result.rs b/src/result.rs index 7404fa2f..96450c6d 100644 --- a/src/result.rs +++ b/src/result.rs @@ -1,17 +1,12 @@ //! Module containing error definitions for the evaluation process. -use crate::dynamic::Dynamic; -use crate::parse_error::ParseErrorType; -use crate::token::{Position, NO_POS}; -use crate::utils::ImmutableString; -use crate::INT; - use crate::stdlib::{ boxed::Box, error::Error, fmt, string::{String, ToString}, }; +use crate::{Dynamic, ImmutableString, ParseErrorType, Position, INT, NO_POS}; /// Evaluation result. /// diff --git a/src/scope.rs b/src/scope.rs index 3152a27a..07b8cd11 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -1,9 +1,8 @@ //! Module that defines the `Scope` type representing a function call-stack scope. -use crate::dynamic::{Dynamic, Variant}; -use crate::StaticVec; - +use crate::dynamic::Variant; use crate::stdlib::{borrow::Cow, boxed::Box, iter, string::String, vec::Vec}; +use crate::{Dynamic, StaticVec}; /// Type of an entry in the Scope. #[derive(Debug, Eq, PartialEq, Hash, Copy, Clone)] diff --git a/src/serde_impl/de.rs b/src/serde_impl/de.rs index 8c17824a..a259377a 100644 --- a/src/serde_impl/de.rs +++ b/src/serde_impl/de.rs @@ -1,12 +1,9 @@ //! Implement deserialization support of `Dynamic` for [`serde`](https://crates.io/crates/serde). use super::str::ImmutableStringDeserializer; -use crate::dynamic::{Dynamic, Union}; -use crate::parse_error::{LexError, ParseErrorType}; -use crate::result::EvalAltResult; -use crate::token::NO_POS; -use crate::utils::ImmutableString; - +use crate::dynamic::Union; +use crate::stdlib::{any::type_name, boxed::Box, fmt, string::ToString}; +use crate::{Dynamic, EvalAltResult, ImmutableString, LexError, ParseErrorType, NO_POS}; use serde::de::{ DeserializeSeed, Deserializer, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor, }; @@ -18,8 +15,6 @@ use crate::Array; #[cfg(not(feature = "no_object"))] use crate::Map; -use crate::stdlib::{any::type_name, boxed::Box, fmt, string::ToString}; - /// Deserializer for `Dynamic` which is kept as a reference. /// /// The reference is necessary because the deserialized type may hold references diff --git a/src/serde_impl/ser.rs b/src/serde_impl/ser.rs index 04cc03fd..97ef4bfb 100644 --- a/src/serde_impl/ser.rs +++ b/src/serde_impl/ser.rs @@ -1,22 +1,18 @@ //! Implement serialization support of `Dynamic` for [`serde`](https://crates.io/crates/serde). -use crate::dynamic::Dynamic; -use crate::result::EvalAltResult; -use crate::token::NO_POS; - -#[cfg(not(feature = "no_index"))] -use crate::Array; - -#[cfg(not(feature = "no_object"))] -use crate::Map; - +use crate::stdlib::{boxed::Box, fmt, string::ToString}; +use crate::{Dynamic, EvalAltResult, NO_POS}; use serde::ser::{ Error, SerializeMap, SerializeSeq, SerializeStruct, SerializeTuple, SerializeTupleStruct, Serializer, }; use serde::Serialize; -use crate::stdlib::{boxed::Box, fmt, string::ToString}; +#[cfg(not(feature = "no_index"))] +use crate::Array; + +#[cfg(not(feature = "no_object"))] +use crate::Map; /// Serializer for `Dynamic` which is kept as a reference. pub struct DynamicSerializer { diff --git a/src/serde_impl/str.rs b/src/serde_impl/str.rs index c499ad49..4c98966b 100644 --- a/src/serde_impl/str.rs +++ b/src/serde_impl/str.rs @@ -1,12 +1,8 @@ //! Implement deserialization support of `ImmutableString` for [`serde`](https://crates.io/crates/serde). -use crate::result::EvalAltResult; -use crate::token::NO_POS; -use crate::utils::ImmutableString; - -use serde::de::{Deserializer, Visitor}; - use crate::stdlib::{any::type_name, boxed::Box}; +use crate::{EvalAltResult, ImmutableString, NO_POS}; +use serde::de::{Deserializer, Visitor}; /// Deserializer for `ImmutableString`. pub struct ImmutableStringDeserializer<'a> { diff --git a/src/syntax.rs b/src/syntax.rs index a7214eec..77527fab 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -1,20 +1,18 @@ //! Module implementing custom syntax for `Engine`. use crate::ast::Expr; -use crate::dynamic::Dynamic; -use crate::engine::{Engine, EvalContext, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT}; -use crate::fn_native::{SendSync, Shared}; -use crate::parse_error::{LexError, ParseError}; -use crate::result::EvalAltResult; -use crate::token::{is_valid_identifier, Position, Token, NO_POS}; -use crate::utils::ImmutableString; -use crate::StaticVec; - +use crate::engine::{EvalContext, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT}; +use crate::fn_native::SendSync; use crate::stdlib::{ boxed::Box, format, string::{String, ToString}, }; +use crate::token::{is_valid_identifier, Token}; +use crate::{ + Dynamic, Engine, EvalAltResult, ImmutableString, LexError, ParseError, Position, Shared, + StaticVec, NO_POS, +}; /// A general expression evaluation trait object. #[cfg(not(feature = "sync"))] diff --git a/src/token.rs b/src/token.rs index ba12ff22..cdf48dd4 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1,17 +1,9 @@ //! Main module defining the lexer and parser. use crate::engine::{ - Engine, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, + KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_IS_DEF_FN, KEYWORD_IS_DEF_VAR, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF, }; - -use crate::parse_error::LexError; -use crate::StaticVec; -use crate::INT; - -#[cfg(not(feature = "no_float"))] -use crate::FLOAT; - use crate::stdlib::{ borrow::Cow, boxed::Box, @@ -20,6 +12,10 @@ use crate::stdlib::{ str::{Chars, FromStr}, string::{String, ToString}, }; +use crate::{Engine, LexError, StaticVec, INT}; + +#[cfg(not(feature = "no_float"))] +use crate::FLOAT; type LERR = LexError; diff --git a/src/unsafe.rs b/src/unsafe.rs index ed859735..eca454fa 100644 --- a/src/unsafe.rs +++ b/src/unsafe.rs @@ -1,7 +1,6 @@ //! A helper module containing unsafe utility functions. use crate::dynamic::Variant; - use crate::stdlib::{ any::{Any, TypeId}, boxed::Box, diff --git a/src/utils.rs b/src/utils.rs index 0ecf321c..173ea9bf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,7 +1,6 @@ //! Module containing various utility types and functions. -use crate::fn_native::{shared_make_mut, shared_take, Shared}; - +use crate::fn_native::{shared_make_mut, shared_take}; use crate::stdlib::{ any::TypeId, borrow::Borrow, @@ -14,6 +13,7 @@ use crate::stdlib::{ str::FromStr, string::{String, ToString}, }; +use crate::Shared; /// A hasher that only takes one single `u64` and returns it as a hash key. ///