11use super :: super :: { AsContext , AsContextMut , StoreContext , StoreContextMut } ;
2- use crate :: { Engine , Error , Extern , Instance } ;
2+ use crate :: { engine :: Inst , Engine , Error , Extern } ;
33
44/// Represents the caller’s context when creating a host function via [`Func::wrap`].
55///
@@ -10,18 +10,18 @@ pub struct Caller<'a, T> {
1010 /// This is `Some` if the host function was called from a Wasm function
1111 /// since all Wasm function are associated to a module instance.
1212 /// This usually is `None` if the host function was called from the host side.
13- instance : Option < Instance > ,
13+ instance : Option < Inst > ,
1414}
1515
1616impl < ' a , T > Caller < ' a , T > {
1717 /// Creates a new [`Caller`] from the given store context and [`Instance`] handle.
18- pub ( crate ) fn new < C > ( ctx : & ' a mut C , instance : Option < & Instance > ) -> Self
18+ pub ( crate ) fn new < C > ( ctx : & ' a mut C , instance : Option < Inst > ) -> Self
1919 where
2020 C : AsContextMut < Data = T > ,
2121 {
2222 Self {
2323 ctx : ctx. as_context_mut ( ) ,
24- instance : instance . copied ( ) ,
24+ instance,
2525 }
2626 }
2727
@@ -30,8 +30,11 @@ impl<'a, T> Caller<'a, T> {
3030 /// Returns `None` if there is no associated [`Instance`] of the caller
3131 /// or if the caller does not provide an export under the name `name`.
3232 pub fn get_export ( & self , name : & str ) -> Option < Extern > {
33- self . instance
34- . and_then ( |instance| instance. get_export ( self , name) )
33+ let Some ( instance) = & self . instance else {
34+ return None ;
35+ } ;
36+ let instance = unsafe { instance. as_ref ( ) } ;
37+ instance. get_export ( name)
3538 }
3639
3740 /// Returns a shared reference to the user provided host data.
0 commit comments