referrerpolicy=no-referrer-when-downgrade

Trait WeightToken

Source
pub trait WeightToken<T: Config>:
    Copy
    + Clone
    + TestAuxiliaries {
    // Required method
    fn weight(&self) -> Weight;

    // Provided method
    fn influence_lowest_weight_limit(&self) -> bool { ... }
}
Expand description

This trait represents a token that can be used for charging WeightMeter. There is no other way of charging it.

Implementing type is expected to be super lightweight hence Copy (Clone is added for consistency). If inlined there should be no observable difference compared to a hand-written code.

Required Methods§

Source

fn weight(&self) -> Weight

Return the amount of weight that should be taken by this token.

This function should be really lightweight and must not fail. It is not expected that implementors will query the storage or do any kinds of heavy operations.

That said, implementors of this function still can run into overflows while calculating the amount. In this case it is ok to use saturating operations since on overflow they will return max_value which should consume all weight.

Provided Methods§

Source

fn influence_lowest_weight_limit(&self) -> bool

Returns true if this token is expected to influence the lowest weight limit.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§