Implement Clone for ModuleInstance

...because of the contained Rc it's otherwise
just a shallow clone, not a deep.
This commit is contained in:
Michael Mueller 2019-06-25 12:51:57 +02:00
parent 327d93c785
commit a1ea2d689f
No known key found for this signature in database
GPG Key ID: 95756F716F423159
1 changed files with 25 additions and 0 deletions

View File

@ -169,6 +169,31 @@ pub struct ModuleInstance {
exports: RefCell<BTreeMap<String, ExternVal>>,
}
impl Clone for ModuleInstance {
fn clone(&self) -> Self {
let signatures = self.signatures.borrow();
let vec = &(*signatures);
let signatures = vec
.iter()
.map(|inner_rc| {
let signature = &**inner_rc;
let signature_clone = signature.clone();
Rc::new(signature_clone)
})
.collect();
let signatures = RefCell::new(signatures);
ModuleInstance {
signatures,
tables: self.tables.clone(),
funcs: self.funcs.clone(),
memories: self.memories.clone(),
globals: self.globals.clone(),
exports: self.exports.clone(),
}
}
}
impl ModuleInstance {
fn default() -> Self {
ModuleInstance {