Skip to content

Commit

Permalink
Use Into/TryInto to convert between types
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Dec 16, 2020
1 parent 180983a commit 69f54e6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/middlewares/src/metering.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! `metering` is a middleware for tracking how many operators are executed in total
//! and putting a limit on the total number of operators executed.
use std::convert::TryInto;
use std::fmt;
use std::sync::Mutex;
use wasmer::wasmparser::{
Operator, Result as WpResult, Type as WpType, TypeOrFuncType as WpTypeOrFuncType,
};
use wasmer::{
ExportIndex, FunctionMiddleware, GlobalInit, GlobalType, Instance, LocalFunctionIndex,
MiddlewareReaderState, ModuleMiddleware, Mutability, Type, Value,
MiddlewareReaderState, ModuleMiddleware, Mutability, Type,
};
use wasmer_types::GlobalIndex;
use wasmer_vm::ModuleInfo;
Expand Down Expand Up @@ -62,7 +63,8 @@ impl<F: Fn(&Operator) -> u64 + Copy + Clone + Send + Sync> Metering<F> {
.get_global("remaining_points")
.expect("Can't get `remaining_points` from Instance")
.get()
.unwrap_i64() as _
.try_into()
.expect("`remaining_points` from Instance has wrong type")
}

/// Set the provided remaining points in an Instance.
Expand All @@ -73,7 +75,7 @@ impl<F: Fn(&Operator) -> u64 + Copy + Clone + Send + Sync> Metering<F> {
.exports
.get_global("remaining_points")
.expect("Can't get `remaining_points` from Instance")
.set(Value::I64(points as _))
.set(points.into())
.expect("Can't set `remaining_points` in Instance");
}
}
Expand Down

0 comments on commit 69f54e6

Please sign in to comment.