FileSystemCache

Struct FileSystemCache 

Source
pub struct FileSystemCache { /* private fields */ }
Expand description

Representation of a directory that contains compiled wasm artifacts.

The FileSystemCache type implements the Cache trait, which allows it to be used generically when some sort of cache is required.

§Usage:

use wasmer_runtime::cache::{Cache, FileSystemCache, WasmHash};

fn store_module(module: Module) -> Result<Module, CacheError> {
    // Create a new file system cache.
    // This is unsafe because we can't ensure that the artifact wasn't
    // corrupted or tampered with.
    let mut fs_cache = unsafe { FileSystemCache::new("some/directory/goes/here")? };
    // Compute a key for a given WebAssembly binary
    let key = WasmHash::generate(&[]);
    // Store a module into the cache given a key
    fs_cache.store(key, module.clone())?;
    Ok(module)
}

Implementations§

Source§

impl FileSystemCache

Source

pub unsafe fn new<P: Into<PathBuf>>(path: P) -> Result<Self>

Construct a new FileSystemCache around the specified directory. The contents of the cache are stored in sub-versioned directories.

§Note:

This method is unsafe because there’s no way to ensure the artifacts stored in this cache haven’t been corrupted or tampered with.

Trait Implementations§

Source§

impl Cache for FileSystemCache

Source§

type LoadError = Error

Error type to return when load error occurs
Source§

type StoreError = Error

Error type to return when store error occurs
Source§

fn load(&self, key: WasmHash) -> Result<Module, CacheError>

loads a module using the default Backend
Source§

fn load_with_backend( &self, key: WasmHash, backend: Backend, ) -> Result<Module, CacheError>

loads a cached module using a specific Backend
Source§

fn store(&mut self, key: WasmHash, module: Module) -> Result<(), CacheError>

Store a module into the cache with the given key

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.