From beea4e31c900b85b5891642880a7a0203563414c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 25 Jun 2019 12:35:51 +0100 Subject: [PATCH] rust: implement Deref trait for EvmcContainer --- bindings/rust/evmc-declare/src/lib.rs | 2 ++ bindings/rust/evmc-vm/src/container.rs | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bindings/rust/evmc-declare/src/lib.rs b/bindings/rust/evmc-declare/src/lib.rs index 4ea20c995..d58de0074 100644 --- a/bindings/rust/evmc-declare/src/lib.rs +++ b/bindings/rust/evmc-declare/src/lib.rs @@ -334,6 +334,8 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream { code_size: usize ) -> ::evmc_vm::ffi::evmc_result { + use evmc_vm::EvmcVm; + assert!(!msg.is_null()); assert!(!context.is_null()); assert!(!instance.is_null()); diff --git a/bindings/rust/evmc-vm/src/container.rs b/bindings/rust/evmc-vm/src/container.rs index a8af3400d..e81d0c69c 100644 --- a/bindings/rust/evmc-vm/src/container.rs +++ b/bindings/rust/evmc-vm/src/container.rs @@ -4,8 +4,8 @@ */ use crate::EvmcVm; -use crate::ExecutionContext; -use crate::ExecutionResult; + +use std::ops::Deref; /// Container struct for EVMC instances and user-defined data. pub struct EvmcContainer { @@ -33,9 +33,15 @@ impl EvmcContainer { pub unsafe fn into_ffi_pointer(boxed: Box) -> *const ::evmc_sys::evmc_instance { Box::into_raw(boxed) as *const ::evmc_sys::evmc_instance } +} + +impl Deref for EvmcContainer +where + T: EvmcVm, +{ + type Target = T; - // TODO: Maybe this can just be done with the Deref trait. - pub fn execute(&self, code: &[u8], context: &ExecutionContext) -> ExecutionResult { - self.vm.execute(code, context) + fn deref(&self) -> &Self::Target { + &self.vm } }