From 4fdd58f2206674cd1587e759e5e85c3a1ad7cce4 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 13 Feb 2021 10:56:09 +0800 Subject: [PATCH] Change AST filters to Fn from FnMut. --- RELEASES.md | 1 + src/ast.rs | 14 +++++++------- src/engine_api.rs | 8 ++++---- src/module/mod.rs | 12 ++++++------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 18f3ffd1..ebf76003 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -19,6 +19,7 @@ Breaking changes * trigonometry functions now take radians and return radians instead of degrees * `Dynamic::into_shared` is no longer available under `no_closure`. It used to panic. * `Token::is_operator` is renamed to `Token::is_symbol`. +* `AST::clone_functions_only_filtered`, `AST::merge_filtered`, `AST::combine_filtered` and `AST::retain_functions` now take `Fn` instead of `FnMut` as the filter predicate. New features ------------ diff --git a/src/ast.rs b/src/ast.rs index 8b91d7de..142fbf1b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -346,10 +346,10 @@ impl AST { #[inline(always)] pub fn clone_functions_only_filtered( &self, - mut filter: impl FnMut(FnNamespace, FnAccess, bool, &str, usize) -> bool, + filter: impl Fn(FnNamespace, FnAccess, bool, &str, usize) -> bool, ) -> Self { let mut functions: Module = Default::default(); - functions.merge_filtered(&self.functions, &mut filter); + functions.merge_filtered(&self.functions, &filter); Self { source: self.source.clone(), statements: Default::default(), @@ -531,7 +531,7 @@ impl AST { pub fn merge_filtered( &self, other: &Self, - mut filter: impl FnMut(FnNamespace, FnAccess, bool, &str, usize) -> bool, + filter: impl Fn(FnNamespace, FnAccess, bool, &str, usize) -> bool, ) -> Self { let Self { statements, @@ -553,7 +553,7 @@ impl AST { let source = other.source.clone().or_else(|| self.source.clone()); let mut functions = functions.as_ref().clone(); - functions.merge_filtered(&other.functions, &mut filter); + functions.merge_filtered(&other.functions, &filter); if let Some(source) = source { Self::new_with_source(ast, functions, source) @@ -616,11 +616,11 @@ impl AST { pub fn combine_filtered( &mut self, other: Self, - mut filter: impl FnMut(FnNamespace, FnAccess, bool, &str, usize) -> bool, + filter: impl Fn(FnNamespace, FnAccess, bool, &str, usize) -> bool, ) -> &mut Self { self.statements.extend(other.statements.into_iter()); if !other.functions.is_empty() { - shared_make_mut(&mut self.functions).merge_filtered(&other.functions, &mut filter); + shared_make_mut(&mut self.functions).merge_filtered(&other.functions, &filter); } self } @@ -653,7 +653,7 @@ impl AST { #[inline(always)] pub fn retain_functions( &mut self, - filter: impl FnMut(FnNamespace, FnAccess, &str, usize) -> bool, + filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool, ) -> &mut Self { if !self.functions.is_empty() { shared_make_mut(&mut self.functions).retain_script_functions(filter); diff --git a/src/engine_api.rs b/src/engine_api.rs index ebecaa40..f45403a3 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -699,11 +699,11 @@ impl Engine { #[inline(always)] 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, + get_fn: impl Fn(&mut T, X) -> U + SendSync + 'static, + set_fn: impl Fn(&mut T, X, U) -> () + SendSync + 'static, ) -> &mut Self { - self.register_indexer_get(getter) - .register_indexer_set(setter) + self.register_indexer_get(get_fn) + .register_indexer_set(set_fn) } /// Register a shared [`Module`] into the global namespace of [`Engine`]. /// diff --git a/src/module/mod.rs b/src/module/mod.rs index 181d4f3b..0aba0ce7 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -1334,12 +1334,12 @@ impl Module { #[inline(always)] pub fn set_indexer_get_set_fn( &mut self, - getter: impl Fn(&mut A, B) -> Result> + SendSync + 'static, - setter: impl Fn(&mut A, B, T) -> Result<(), Box> + SendSync + 'static, + get_fn: impl Fn(&mut A, B) -> Result> + SendSync + 'static, + set_fn: impl Fn(&mut A, B, T) -> Result<(), Box> + SendSync + 'static, ) -> (NonZeroU64, NonZeroU64) { ( - self.set_indexer_get_fn(getter), - self.set_indexer_set_fn(setter), + self.set_indexer_get_fn(get_fn), + self.set_indexer_set_fn(set_fn), ) } @@ -1570,7 +1570,7 @@ impl Module { pub(crate) fn merge_filtered( &mut self, other: &Self, - mut _filter: &mut impl FnMut(FnNamespace, FnAccess, bool, &str, usize) -> bool, + _filter: &impl Fn(FnNamespace, FnAccess, bool, &str, usize) -> bool, ) -> &mut Self { #[cfg(not(feature = "no_function"))] other.modules.iter().for_each(|(k, v)| { @@ -1625,7 +1625,7 @@ impl Module { #[inline] pub(crate) fn retain_script_functions( &mut self, - mut filter: impl FnMut(FnNamespace, FnAccess, &str, usize) -> bool, + filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool, ) -> &mut Self { self.functions.retain( |_,