pub struct Metering<F: Fn(&Operator<'_>) -> u64 + Send + Sync> { /* private fields */ }
Expand description

The module-level metering middleware.

Panic

An instance of Metering should not be shared among different modules, since it tracks module-specific information like the global index to store metering state. Attempts to use a Metering instance from multiple modules will result in a panic.

Example

use std::sync::Arc;
use wasmer::{wasmparser::Operator, CompilerConfig};
use wasmer_middlewares::Metering;

fn create_metering_middleware(compiler_config: &mut dyn CompilerConfig) {
    // Let's define a dummy cost function,
    // which counts 1 for all operators.
    let cost_function = |_operator: &Operator| -> u64 { 1 };

    // Let's define the initial limit.
    let initial_limit = 10;

    // Let's creating the metering middleware.
    let metering = Arc::new(Metering::new(
        initial_limit,
        cost_function
    ));

    // Finally, let's push the middleware.
    compiler_config.push_middleware(metering);
}

Implementations§

source§

impl<F: Fn(&Operator<'_>) -> u64 + Send + Sync> Metering<F>

source

pub fn new(initial_limit: u64, cost_function: F) -> Self

Creates a Metering middleware.

Trait Implementations§

source§

impl<F: Fn(&Operator<'_>) -> u64 + Send + Sync> Debug for Metering<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F: Fn(&Operator<'_>) -> u64 + Send + Sync + 'static> ModuleMiddleware for Metering<F>

source§

fn generate_function_middleware( &self, _: LocalFunctionIndex ) -> Box<dyn FunctionMiddleware>

Generates a FunctionMiddleware for a given function.

source§

fn transform_module_info(&self, module_info: &mut ModuleInfo)

Transforms a ModuleInfo struct in-place. This is called before application on functions begins.

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for Metering<F>where F: RefUnwindSafe,

§

impl<F> Send for Metering<F>

§

impl<F> Sync for Metering<F>

§

impl<F> Unpin for Metering<F>

§

impl<F> UnwindSafe for Metering<F>where F: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcastable for Twhere T: Any + Send + Sync + 'static,

§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn