From 489b1ca00eaeee6daf14a02e0652ffa1f95da75a Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 15 Aug 2020 00:08:00 +0800 Subject: [PATCH] Add Module::combine. --- RELEASES.md | 1 + src/module.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index fcf498cf..b753bba3 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -8,6 +8,7 @@ New features ------------ * Adds `Engine::register_get_result`, `Engine::register_set_result`, `Engine::register_indexer_get_result`, `Engine::register_indexer_set_result` API. +* Adds `Module::combine` to combine two modules. Version 0.18.1 diff --git a/src/module.rs b/src/module.rs index dbb416a2..28c64ff0 100644 --- a/src/module.rs +++ b/src/module.rs @@ -928,6 +928,18 @@ impl Module { self.all_functions.get(&hash_qualified_fn) } + /// Combine another module into this module. + /// The other module is consumed to merge into this module. + pub fn combine(&mut self, other: Self) -> &mut Self { + self.variables.extend(other.variables.into_iter()); + self.functions.extend(other.functions.into_iter()); + self.type_iterators.extend(other.type_iterators.into_iter()); + self.all_functions.clear(); + self.all_variables.clear(); + self.indexed = false; + self + } + /// Merge another module into this module. pub fn merge(&mut self, other: &Self) -> &mut Self { self.merge_filtered(other, |_, _, _| true)