Implement Eq and PartialEq for ScriptFnMetadata that sorts on function signature.

This commit is contained in:
Stephen Chung 2021-05-04 10:19:08 +08:00
parent c61b118037
commit 13c620de4b
2 changed files with 18 additions and 1 deletions

View File

@ -148,6 +148,23 @@ impl<'a> Into<ScriptFnMetadata<'a>> for &'a ScriptFnDef {
} }
} }
#[cfg(not(feature = "no_function"))]
impl std::cmp::PartialOrd for ScriptFnMetadata<'_> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
#[cfg(not(feature = "no_function"))]
impl std::cmp::Ord for ScriptFnMetadata<'_> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self.name.cmp(other.name) {
std::cmp::Ordering::Equal => self.params.len().cmp(&other.params.len()),
cmp => cmp,
}
}
}
/// Compiled AST (abstract syntax tree) of a Rhai script. /// Compiled AST (abstract syntax tree) of a Rhai script.
/// ///
/// # Thread Safety /// # Thread Safety

View File

@ -1456,7 +1456,7 @@ impl Module {
.filter(|f| f.func.is_script()) .filter(|f| f.func.is_script())
.for_each(|f| { .for_each(|f| {
// Encapsulate AST environment // Encapsulate AST environment
let mut func = crate::fn_native::shared_take_or_clone(f.func.get_fn_def().clone()); let mut func = f.func.get_fn_def().as_ref().clone();
func.lib = Some(ast.shared_lib()); func.lib = Some(ast.shared_lib());
func.mods = func_mods.clone(); func.mods = func_mods.clone();
module.set_script_fn(func); module.set_script_fn(func);