Move memory store cloning into the wasmer crate

This commit is contained in:
Syrus Akbary
2023-03-16 15:23:16 -07:00
parent c00f1fda65
commit a5500fbc6f
8 changed files with 80 additions and 90 deletions

View File

@@ -142,6 +142,21 @@ impl Memory {
self.0.try_clone(store)
}
/// Attempts to clone this memory (if its clonable) in a new store
pub fn duplicate_in_store(
&self,
store: &impl AsStoreRef,
new_store: &mut impl AsStoreMut,
) -> Option<Self> {
if !self.ty(store).shared {
// We should only be able to duplicate in a new store if the memory is shared
return None;
}
self.try_clone(&store)
.and_then(|mut memory| memory.duplicate().ok())
.map(|new_memory| Self::new_from_existing(new_store, new_memory.into()))
}
/// To `VMExtern`.
pub(crate) fn to_vm_extern(&self) -> VMExtern {
self.0.to_vm_extern()