Skip to content

Commit 8d46f7f

Browse files
author
Michael-F-Bryan
committed
Make AsStoreRef and friends work for anything that derefs to an AsStoreRef
1 parent b1a94df commit 8d46f7f

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

lib/api/src/sys/store.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::sys::tunables::BaseTunables;
22
use derivative::Derivative;
3-
use std::fmt;
3+
use std::{
4+
fmt,
5+
ops::{Deref, DerefMut},
6+
};
47
#[cfg(feature = "compiler")]
58
use wasmer_compiler::{AsEngineRef, Engine, EngineBuilder, EngineRef, Tunables};
69
use wasmer_types::OnCalledAction;
@@ -220,13 +223,6 @@ impl AsEngineRef for Store {
220223
}
221224
}
222225

223-
#[cfg(feature = "compiler")]
224-
impl AsEngineRef for &Store {
225-
fn as_engine_ref(&self) -> EngineRef<'_> {
226-
EngineRef::new(&self.engine)
227-
}
228-
}
229-
230226
#[cfg(feature = "compiler")]
231227
impl AsEngineRef for StoreRef<'_> {
232228
fn as_engine_ref(&self) -> EngineRef<'_> {
@@ -374,21 +370,26 @@ impl AsStoreMut for StoreMut<'_> {
374370
}
375371
}
376372

377-
impl<T: AsStoreRef> AsStoreRef for &'_ T {
373+
impl<P> AsStoreRef for P
374+
where
375+
P: Deref,
376+
P::Target: AsStoreRef,
377+
{
378378
fn as_store_ref(&self) -> StoreRef<'_> {
379-
T::as_store_ref(*self)
379+
(**self).as_store_ref()
380380
}
381381
}
382-
impl<T: AsStoreRef> AsStoreRef for &'_ mut T {
383-
fn as_store_ref(&self) -> StoreRef<'_> {
384-
T::as_store_ref(*self)
385-
}
386-
}
387-
impl<T: AsStoreMut> AsStoreMut for &'_ mut T {
382+
383+
impl<P> AsStoreMut for P
384+
where
385+
P: DerefMut,
386+
P::Target: AsStoreMut,
387+
{
388388
fn as_store_mut(&mut self) -> StoreMut<'_> {
389-
T::as_store_mut(*self)
389+
(**self).as_store_mut()
390390
}
391+
391392
fn objects_mut(&mut self) -> &mut StoreObjects {
392-
T::objects_mut(*self)
393+
(**self).objects_mut()
393394
}
394395
}

lib/compiler/src/engine/engineref.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::ops::Deref;
2+
13
use super::Engine;
24
use crate::Tunables;
35

@@ -37,3 +39,13 @@ impl AsEngineRef for EngineRef<'_> {
3739
EngineRef { inner: self.inner }
3840
}
3941
}
42+
43+
impl<P> AsEngineRef for P
44+
where
45+
P: Deref,
46+
P::Target: AsEngineRef,
47+
{
48+
fn as_engine_ref(&self) -> EngineRef<'_> {
49+
(**self).as_engine_ref()
50+
}
51+
}

0 commit comments

Comments
 (0)