Skip to content

Commit

Permalink
Add EvmcResult wrapper in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Mar 13, 2019
1 parent 139985d commit eb62c72
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions bindings/rust/evmc-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ edition = "2018"

[dependencies]
evmc-sys = { path = "../evmc-sys" }
libc = "0.2.48"
29 changes: 29 additions & 0 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,32 @@ pub use evmc_sys as ffi;
// TODO: Add convenient helpers for evmc_result
// TODO: Add convenient helpers for evmc_execute
// TODO: Add a derive macro here for creating evmc_create

//pub fn destroy_result(&mut evmc_result)

/// EVMC result structure.
pub struct EvmcResult(Box<ffi::evmc_result>);

impl EvmcResult {
pub fn release_result(self) {
if let Some(release_fn) = self.0.release {
unsafe {
release_fn(Box::into_raw(self.0));
}
}
}

pub fn set_release_fn(&mut self, f: extern "C" fn(*const ffi::evmc_result)) {
self.0.release = Some(f);
}

pub fn into_raw(self) -> *const ffi::evmc_result {
Box::into_raw(self.0)
}

pub fn set_status(&mut self, code: ffi::evmc_status_code) {}

pub fn set_gas_left(&mut self, gas: i64) {
self.0.gas_left = gas;
}
}

0 comments on commit eb62c72

Please sign in to comment.