Function wasmer_middlewares::metering::get_remaining_points
source · pub fn get_remaining_points(
ctx: &mut impl AsStoreMut,
instance: &Instance,
) -> MeteringPoints
Expand description
Get the remaining points in an [Instance
][wasmer::Instance].
Note: This can be used in a headless engine after an ahead-of-time compilation as all required state lives in the instance.
§Panic
The [Instance
][wasmer::Instance) must have been processed with
the Metering
middleware at compile time, otherwise this will
panic.
§Example
use wasmer::Instance;
use wasmer::AsStoreMut;
use wasmer_middlewares::metering::{get_remaining_points, MeteringPoints};
/// Check whether the instance can continue to run based on the
/// number of remaining points.
fn can_continue_to_run(store: &mut impl AsStoreMut, instance: &Instance) -> bool {
matches!(get_remaining_points(store, instance), MeteringPoints::Remaining(points) if points > 0)
}