mirror of https://github.com/status-im/evmc.git
Merge pull request #330 from ethereum/rust-container-deref
rust: implement Deref trait for EvmcContainer
This commit is contained in:
commit
e6eab307fd
|
@ -334,6 +334,8 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
|
||||||
code_size: usize
|
code_size: usize
|
||||||
) -> ::evmc_vm::ffi::evmc_result
|
) -> ::evmc_vm::ffi::evmc_result
|
||||||
{
|
{
|
||||||
|
use evmc_vm::EvmcVm;
|
||||||
|
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
assert!(!context.is_null());
|
assert!(!context.is_null());
|
||||||
assert!(!instance.is_null());
|
assert!(!instance.is_null());
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::EvmcVm;
|
use crate::EvmcVm;
|
||||||
use crate::ExecutionContext;
|
|
||||||
use crate::ExecutionResult;
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// Container struct for EVMC instances and user-defined data.
|
/// Container struct for EVMC instances and user-defined data.
|
||||||
pub struct EvmcContainer<T: EvmcVm + Sized> {
|
pub struct EvmcContainer<T: EvmcVm + Sized> {
|
||||||
|
@ -33,9 +33,15 @@ impl<T: EvmcVm + Sized> EvmcContainer<T> {
|
||||||
pub unsafe fn into_ffi_pointer(boxed: Box<Self>) -> *const ::evmc_sys::evmc_instance {
|
pub unsafe fn into_ffi_pointer(boxed: Box<Self>) -> *const ::evmc_sys::evmc_instance {
|
||||||
Box::into_raw(boxed) as *const ::evmc_sys::evmc_instance
|
Box::into_raw(boxed) as *const ::evmc_sys::evmc_instance
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Maybe this can just be done with the Deref<Target = T> trait.
|
impl<T> Deref for EvmcContainer<T>
|
||||||
pub fn execute(&self, code: &[u8], context: &ExecutionContext) -> ExecutionResult {
|
where
|
||||||
self.vm.execute(code, context)
|
T: EvmcVm,
|
||||||
|
{
|
||||||
|
type Target = T;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.vm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue