Merge pull request #3433 from dsherret/as_engine_ref_deserialize

Module.deserialize - accept AsEngineRef
This commit is contained in:
Syrus Akbary
2022-12-22 17:20:14 -08:00
committed by GitHub
3 changed files with 10 additions and 10 deletions

View File

@@ -307,11 +307,11 @@ impl Module {
/// # }
/// ```
pub unsafe fn deserialize(
store: &impl AsStoreRef,
engine: &impl AsEngineRef,
bytes: impl IntoBytes,
) -> Result<Self, DeserializeError> {
let bytes = bytes.into_bytes();
let artifact = store.as_store_ref().engine().deserialize(&bytes)?;
let artifact = engine.as_engine_ref().engine().deserialize(&bytes)?;
Ok(Self::from_artifact(artifact))
}
@@ -334,11 +334,11 @@ impl Module {
/// # }
/// ```
pub unsafe fn deserialize_from_file(
store: &impl AsStoreRef,
engine: &impl AsEngineRef,
path: impl AsRef<Path>,
) -> Result<Self, DeserializeError> {
let artifact = store
.as_store_ref()
let artifact = engine
.as_engine_ref()
.engine()
.deserialize_from_file(path.as_ref())?;
Ok(Self::from_artifact(artifact))

View File

@@ -4,7 +4,7 @@
use crate::hash::Hash;
use std::error::Error;
use wasmer::{Module, Store};
use wasmer::{Module, AsEngineRef};
/// A generic cache for storing and loading compiled wasm modules.
pub trait Cache {
@@ -17,7 +17,7 @@ pub trait Cache {
///
/// # Safety
/// This function is unsafe as the cache store could be tampered with.
unsafe fn load(&self, store: &Store, key: Hash) -> Result<Module, Self::DeserializeError>;
unsafe fn load(&self, engine: &impl AsEngineRef, key: Hash) -> Result<Module, Self::DeserializeError>;
/// Store a [`Module`] into the cache with the given [`Hash`].
fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError>;

View File

@@ -4,7 +4,7 @@ use crate::hash::Hash;
use std::fs::{create_dir_all, File};
use std::io::{self, Write};
use std::path::PathBuf;
use wasmer::{DeserializeError, Module, SerializeError, Store};
use wasmer::{DeserializeError, Module, SerializeError, AsEngineRef};
/// Representation of a directory that contains compiled wasm artifacts.
///
@@ -91,14 +91,14 @@ impl Cache for FileSystemCache {
type DeserializeError = DeserializeError;
type SerializeError = SerializeError;
unsafe fn load(&self, store: &Store, key: Hash) -> Result<Module, Self::DeserializeError> {
unsafe fn load(&self, engine: &impl AsEngineRef, key: Hash) -> Result<Module, Self::DeserializeError> {
let filename = if let Some(ref ext) = self.ext {
format!("{}.{}", key.to_string(), ext)
} else {
key.to_string()
};
let path = self.path.join(filename);
Module::deserialize_from_file(store, path)
Module::deserialize_from_file(engine, path)
}
fn store(&mut self, key: Hash, module: &Module) -> Result<(), Self::SerializeError> {