Struct wasmer_middlewares::metering::Metering
source · 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§
Trait Implementations§
source§impl<F: Fn(&Operator<'_>) -> u64 + Send + Sync + 'static> ModuleMiddleware for Metering<F>
impl<F: Fn(&Operator<'_>) -> u64 + Send + Sync + 'static> ModuleMiddleware for Metering<F>
source§fn generate_function_middleware(
&self,
_: LocalFunctionIndex
) -> Box<dyn FunctionMiddleware>
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)
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§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
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,
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>
fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.
§impl<T> Upcastable for Twhere
T: Any + Send + Sync + 'static,
impl<T> Upcastable for Twhere T: Any + Send + Sync + 'static,
§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref
§fn upcast_any_box(self: Box<T>) -> Box<dyn Any>
fn upcast_any_box(self: Box<T>) -> Box<dyn Any>
upcast boxed dyn