diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index 6f7cf6ac9fd..9636bfa1163 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -1,6 +1,9 @@ use crate::sys::tunables::BaseTunables; use derivative::Derivative; -use std::fmt; +use std::{ + fmt, + ops::{Deref, DerefMut}, +}; #[cfg(feature = "compiler")] use wasmer_compiler::{AsEngineRef, Engine, EngineBuilder, EngineRef, Tunables}; use wasmer_types::OnCalledAction; @@ -220,13 +223,6 @@ impl AsEngineRef for Store { } } -#[cfg(feature = "compiler")] -impl AsEngineRef for &Store { - fn as_engine_ref(&self) -> EngineRef<'_> { - EngineRef::new(&self.engine) - } -} - #[cfg(feature = "compiler")] impl AsEngineRef for StoreRef<'_> { fn as_engine_ref(&self) -> EngineRef<'_> { @@ -374,21 +370,26 @@ impl AsStoreMut for StoreMut<'_> { } } -impl AsStoreRef for &'_ T { +impl

AsStoreRef for P +where + P: Deref, + P::Target: AsStoreRef, +{ fn as_store_ref(&self) -> StoreRef<'_> { - T::as_store_ref(*self) + (**self).as_store_ref() } } -impl AsStoreRef for &'_ mut T { - fn as_store_ref(&self) -> StoreRef<'_> { - T::as_store_ref(*self) - } -} -impl AsStoreMut for &'_ mut T { + +impl

AsStoreMut for P +where + P: DerefMut, + P::Target: AsStoreMut, +{ fn as_store_mut(&mut self) -> StoreMut<'_> { - T::as_store_mut(*self) + (**self).as_store_mut() } + fn objects_mut(&mut self) -> &mut StoreObjects { - T::objects_mut(*self) + (**self).objects_mut() } } diff --git a/lib/compiler/src/engine/engineref.rs b/lib/compiler/src/engine/engineref.rs index 107cd9b1153..f5fa32aa551 100644 --- a/lib/compiler/src/engine/engineref.rs +++ b/lib/compiler/src/engine/engineref.rs @@ -1,3 +1,5 @@ +use core::ops::Deref; + use super::Engine; use crate::Tunables; @@ -37,3 +39,13 @@ impl AsEngineRef for EngineRef<'_> { EngineRef { inner: self.inner } } } + +impl

AsEngineRef for P +where + P: Deref, + P::Target: AsEngineRef, +{ + fn as_engine_ref(&self) -> EngineRef<'_> { + (**self).as_engine_ref() + } +}