Skip to main content

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::{DeserializeError, SerializeError};
use wasmer_cache::{Cache, FileSystemCache, Hash};

fn store_module(module: &Module, bytes: &[u8]) -> Result<(), SerializeError> {
    // Create a new file system cache.
    let mut fs_cache = FileSystemCache::new("some/directory/goes/here")?;

    // Compute a key for a given WebAssembly binary
    let key = Hash::generate(bytes);

    // Store a module into the cache given a key
    fs_cache.store(key, module)?;

    Ok(())
}

Implementations§

Source§

impl FileSystemCache

Source

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

Construct a new FileSystemCache around the specified directory.

Source

pub fn set_cache_extension(&mut self, ext: Option<impl ToString>)

Set the extension for this cached file.

This is needed for loading native files from Windows, as otherwise loading the library will fail (it requires a .dll extension)

Trait Implementations§

Source§

impl Cache for FileSystemCache

Source§

type DeserializeError = DeserializeError

The deserialization error for the implementation
Source§

type SerializeError = SerializeError

The serialization error for the implementation
Source§

unsafe fn load( &self, store: &Store, key: Hash, ) -> Result<Module, Self::DeserializeError>

Loads a module using the provided Store and [Hash]. Read more
Source§

fn store( &mut self, key: Hash, module: &Module, ) -> Result<(), Self::SerializeError>

Store a Module into the cache with the given [Hash].

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> Same for T

Source§

type Output = T

Should always be Self
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.