Skip to content

Commit

Permalink
Merge pull request #330 from ethereum/rust-container-deref
Browse files Browse the repository at this point in the history
rust: implement Deref trait for EvmcContainer
  • Loading branch information
axic committed Jun 25, 2019
2 parents 32acbfa + beea4e3 commit e6eab30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bindings/rust/evmc-declare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
16 changes: 11 additions & 5 deletions bindings/rust/evmc-vm/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: EvmcVm + Sized> {
Expand Down Expand Up @@ -33,9 +33,15 @@ impl<T: EvmcVm + Sized> EvmcContainer<T> {
pub unsafe fn into_ffi_pointer(boxed: Box<Self>) -> *const ::evmc_sys::evmc_instance {
Box::into_raw(boxed) as *const ::evmc_sys::evmc_instance
}
}

impl<T> Deref for EvmcContainer<T>
where
T: EvmcVm,
{
type Target = T;

// TODO: Maybe this can just be done with the Deref<Target = T> trait.
pub fn execute(&self, code: &[u8], context: &ExecutionContext) -> ExecutionResult {
self.vm.execute(code, context)
fn deref(&self) -> &Self::Target {
&self.vm
}
}

0 comments on commit e6eab30

Please sign in to comment.