pub struct ConstantCostRules { /* private fields */ }
Expand description

A type that implements Rules so that every instruction costs the same.

This is a simplification that is mostly useful for development and testing.

Note

In a production environment it usually makes no sense to assign every instruction the same cost. A proper implemention of Rules should be prived that is probably created by benchmarking.

Implementations§

source§

impl ConstantCostRules

source

pub fn new( instruction_cost: u32, memory_grow_cost: u32, call_per_local_cost: u32 ) -> Self

Create a new ConstantCostRules.

Uses instruction_cost for every instruction and memory_grow_cost to dynamically meter the memory growth instruction.

Trait Implementations§

source§

impl Default for ConstantCostRules

source§

fn default() -> Self

Uses instruction cost of 1 and disables memory growth instrumentation.

source§

impl Rules for ConstantCostRules

source§

fn instruction_cost(&self, _: &Instruction) -> Option<u32>

Returns the cost for the passed instruction. Read more
source§

fn memory_grow_cost(&self) -> MemoryGrowCost

Returns the costs for growing the memory using the memory.grow instruction. Read more
source§

fn call_per_local_cost(&self) -> u32

A surcharge cost to calling a function that is added per local variable of the function.

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>,

§

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>,

§

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.