diff --git a/src/api.rs b/src/api.rs index d69933e9..0af6954f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -125,8 +125,7 @@ impl Engine { /// Register an iterator adapter for a type with the `Engine`. /// This is an advanced feature. pub fn register_iterator(&mut self, f: F) { - self.global_module - .set_iterator(TypeId::of::(), Box::new(f)); + self.global_module.set_iter(TypeId::of::(), Box::new(f)); } /// Register a getter function for a member of a registered type with the `Engine`. diff --git a/src/engine.rs b/src/engine.rs index 2acb7fad..eda78ae0 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -552,7 +552,7 @@ impl Engine { if let Some(func) = self .global_module .get_fn(hashes.0) - .or_else(|| self.packages.get_function(hashes.0)) + .or_else(|| self.packages.get_fn(hashes.0)) { let mut backup: Dynamic = Default::default(); @@ -728,7 +728,7 @@ impl Engine { // First check registered functions self.global_module.contains_fn(hashes.0) // Then check packages - || self.packages.contains_function(hashes.0) + || self.packages.contains_fn(hashes.0) // Then check script-defined functions || state.has_function(hashes.1) } @@ -1573,8 +1573,8 @@ impl Engine { if let Some(iter_fn) = self .global_module - .get_iterator(tid) - .or_else(|| self.packages.get_iterator(tid)) + .get_iter(tid) + .or_else(|| self.packages.get_iter(tid)) { // Add the loop variable let name = x.0.clone(); diff --git a/src/fn_func.rs b/src/fn_func.rs index a595064f..e619ebdf 100644 --- a/src/fn_func.rs +++ b/src/fn_func.rs @@ -92,7 +92,6 @@ macro_rules! def_anonymous_fn { { #[cfg(feature = "sync")] type Output = Box Result> + Send + Sync>; - #[cfg(not(feature = "sync"))] type Output = Box Result>>; diff --git a/src/module.rs b/src/module.rs index 5bc11d74..698004c7 100644 --- a/src/module.rs +++ b/src/module.rs @@ -567,20 +567,6 @@ impl Module { .ok_or_else(|| Box::new(EvalAltResult::ErrorFunctionNotFound(name.to_string(), pos))) } - /// Get the script-defined functions. - /// - /// # Examples - /// - /// ``` - /// use rhai::Module; - /// - /// let mut module = Module::new(); - /// assert_eq!(module.get_fn_lib().len(), 0); - /// ``` - pub fn get_fn_lib(&self) -> &FunctionsLib { - &self.fn_lib - } - /// Get a modules-qualified script-defined functions. /// /// The `u64` hash is calculated by the function `crate::calc_fn_hash`. @@ -720,12 +706,12 @@ impl Module { } /// Does a type iterator exist in the module? - pub fn contains_iterator(&self, id: TypeId) -> bool { + pub fn contains_iter(&self, id: TypeId) -> bool { self.type_iterators.contains_key(&id) } /// Set a type iterator into the module. - pub fn set_iterator(&mut self, typ: TypeId, func: Box) { + pub fn set_iter(&mut self, typ: TypeId, func: Box) { #[cfg(not(feature = "sync"))] self.type_iterators.insert(typ, Rc::new(func)); #[cfg(feature = "sync")] @@ -733,7 +719,7 @@ impl Module { } /// Get the specified type iterator. - pub fn get_iterator(&self, id: TypeId) -> Option<&SharedIteratorFunction> { + pub fn get_iter(&self, id: TypeId) -> Option<&SharedIteratorFunction> { self.type_iterators.get(&id) } } diff --git a/src/optimize.rs b/src/optimize.rs index babb58c0..e03ea76e 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -123,7 +123,7 @@ fn call_fn( global_module .get_fn(hash) - .or_else(|| packages.get_function(hash)) + .or_else(|| packages.get_fn(hash)) .map(|func| func.call(args, pos)) .transpose() } diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 5aed286e..bdfd03aa 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -118,7 +118,7 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, { ); // Register array iterator - lib.set_iterator( + lib.set_iter( TypeId::of::(), Box::new(|arr| Box::new( arr.cast::().into_iter()) as Box> diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index daf57c44..553873e7 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -14,7 +14,7 @@ fn reg_range(lib: &mut Module) where Range: Iterator, { - lib.set_iterator( + lib.set_iter( TypeId::of::>(), Box::new(|source| { Box::new(source.cast::>().map(|x| x.into_dynamic())) @@ -58,7 +58,7 @@ where T: Variant + Clone + PartialOrd, StepRange: Iterator, { - lib.set_iterator( + lib.set_iter( TypeId::of::>(), Box::new(|source| { Box::new(source.cast::>().map(|x| x.into_dynamic())) diff --git a/src/packages/mod.rs b/src/packages/mod.rs index ceebf4bf..5c2a6dd5 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -64,11 +64,11 @@ impl PackagesCollection { self.packages.insert(0, package); } /// Does the specified function hash key exist in the `PackagesCollection`? - pub fn contains_function(&self, hash: u64) -> bool { + pub fn contains_fn(&self, hash: u64) -> bool { self.packages.iter().any(|p| p.contains_fn(hash)) } /// Get specified function via its hash key. - pub fn get_function(&self, hash: u64) -> Option<&Box> { + pub fn get_fn(&self, hash: u64) -> Option<&Box> { self.packages .iter() .map(|p| p.get_fn(hash)) @@ -76,14 +76,14 @@ impl PackagesCollection { .flatten() } /// Does the specified TypeId iterator exist in the `PackagesCollection`? - pub fn contains_iterator(&self, id: TypeId) -> bool { - self.packages.iter().any(|p| p.contains_iterator(id)) + pub fn contains_iter(&self, id: TypeId) -> bool { + self.packages.iter().any(|p| p.contains_iter(id)) } /// Get the specified TypeId iterator. - pub fn get_iterator(&self, id: TypeId) -> Option<&SharedIteratorFunction> { + pub fn get_iter(&self, id: TypeId) -> Option<&SharedIteratorFunction> { self.packages .iter() - .map(|p| p.get_iterator(id)) + .map(|p| p.get_iter(id)) .find(|f| f.is_some()) .flatten() }