pub fn import_function_with_context<
        Args,
        F: ImportableFnWithContext<C, Args> + Send + 'static,
        C: Send + Sync + Clone + 'static,
    >(
        self,
        name: impl ToString,
        ctx: C,
        value: F,
    ) -> Self {
        let env = Env::new(self.garbage.clone(), ctx);

        if F::has_arg() {
            let f = if F::has_return() {
                let wrapped = move |env: &Env<C>, ptr: u32, len: u32| -> u64 {
                    let mut buffer = env.message_buffer();
                    let r = value
                        .call_with_input(&mut buffer, ptr as usize, len as usize, &env.ctx)
                        .unwrap()
                        .map(|p| p.0)
                        .unwrap_or(0);
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                    r
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            } else {
                let wrapped = move |env: &Env<C>, ptr: u32, len: u32| {
                    let mut buffer = env.message_buffer();
                    value
                        .call_with_input(&mut buffer, ptr as usize, len as usize, &env.ctx)
                        .unwrap();
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            };
            self.import(name, f)
        } else {
            let f = if F::has_return() {
                let wrapped = move |env: &Env<C>| -> u64 {
                    let mut buffer = env.message_buffer();
                    let r = value
                        .call_without_input(&mut buffer, &env.ctx)
                        .unwrap()
                        .map(|p| p.0)
                        .unwrap_or(0);
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                    r
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            } else {
                let wrapped = move |env: &Env<C>| {
                    let mut buffer = env.message_buffer();
                    value.call_without_input(&mut buffer, &env.ctx).unwrap();
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            };
            self.import(name, f)
        }
    }
/// Import a function defined in the host into the guest. The function's
/// arguments and return type must all be serializable.
/// An immutable reference to `ctx` will be passed to the function as it's
/// first argument each time it's called.
///
/// NOTE: This method exists due to a limitation in the underlying Waswer
/// engine which currently doesn't support imported closures with
/// captured context. The Wasamer developers have said they are interested
/// in removing that limitation and when they do this method will be
/// removed in favor of `import_function' since context can be more
/// idiomatically handled with captured values.
Import a function defined in the host into the guest. The function's
arguments and return type must all be serializable.
An immutable reference to `ctx` will be passed to the function as it's
first argument each time it's called.

This method exists due to a limitation in the underlying Waswer
engine which currently doesn't support imported closures with
captured context. The Wasamer developers have said they are interested
in removing that limitation and when they do this method will be
removed in favor of `import_function' since context can be more
idiomatically handled with captured values.
Import a function defined in the host into the guest . The function ' s arguments and return type must all be serializable . An immutable reference to ` ctx ` will be passed to the function as it ' s first argument each time it ' s called . This method exists due to a limitation in the underlying Waswer engine which currently doesn ' t support imported closures with captured context . The Wasamer developers have said they are interested in removing that limitation and when they do this method will be removed in favor of ` import_function ' since context can be more idiomatically handled with captured values .
pub fn import_function_with_context<
        Args,
        F: ImportableFnWithContext<C, Args> + Send + 'static,
        C: Send + Sync + Clone + 'static,
    >(
        self,
        name: impl ToString,
        ctx: C,
        value: F,
    ) -> Self {
        let env = Env::new(self.garbage.clone(), ctx);
        if F::has_arg() {
            let f = if F::has_return() {
                let wrapped = move |env: &Env<C>, ptr: u32, len: u32| -> u64 {
                    let mut buffer = env.message_buffer();
                    let r = value
                        .call_with_input(&mut buffer, ptr as usize, len as usize, &env.ctx)
                        .unwrap()
                        .map(|p| p.0)
                        .unwrap_or(0);
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                    r
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            } else {
                let wrapped = move |env: &Env<C>, ptr: u32, len: u32| {
                    let mut buffer = env.message_buffer();
                    value
                        .call_with_input(&mut buffer, ptr as usize, len as usize, &env.ctx)
                        .unwrap();
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            };
            self.import(name, f)
        } else {
            let f = if F::has_return() {
                let wrapped = move |env: &Env<C>| -> u64 {
                    let mut buffer = env.message_buffer();
                    let r = value
                        .call_without_input(&mut buffer, &env.ctx)
                        .unwrap()
                        .map(|p| p.0)
                        .unwrap_or(0);
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                    r
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            } else {
                let wrapped = move |env: &Env<C>| {
                    let mut buffer = env.message_buffer();
                    value.call_without_input(&mut buffer, &env.ctx).unwrap();
                    env.garbage.lock().unwrap().extend(buffer.garbage.drain(..));
                };
                Function::new_native_with_env(&self.store, env, wrapped)
            };
            self.import(name, f)
        }
    }
pub fn import_function_with_context < Args , F : ImportableFnWithContext < C , Args > + Send + ' static , C : Send + Sync + Clone + ' static , > ( self , name : impl ToString , ctx : C , value : F , ) -> Self { let env = Env :: new ( self . garbage . clone ( ) , ctx ) ; if F :: has_arg ( ) { let f = if F :: has_return ( ) { let wrapped = move | env : & Env < C > , ptr : u32 , len : u32 | -> u64 { let mut buffer = env . message_buffer ( ) ; let r = value . call_with_input ( & mut buffer , ptr as usize , len as usize , & env . ctx ) . unwrap ( ) . map ( | p | p . 0 ) . unwrap_or ( 0 ) ; env . garbage . lock ( ) . unwrap ( ) . extend ( buffer . garbage . drain ( .. ) ) ; r } ; Function :: new_native_with_env ( & self . store , env , wrapped ) } else { let wrapped = move | env : & Env < C > , ptr : u32 , len : u32 | { let mut buffer = env . message_buffer ( ) ; value . call_with_input ( & mut buffer , ptr as usize , len as usize , & env . ctx ) . unwrap ( ) ; env . garbage . lock ( ) . unwrap ( ) . extend ( buffer . garbage . drain ( .. ) ) ; } ; Function :: new_native_with_env ( & self . store , env , wrapped ) } ; self . import ( name , f ) } else { let f = if F :: has_return ( ) { let wrapped = move | env : & Env < C > | -> u64 { let mut buffer = env . message_buffer ( ) ; let r = value . call_without_input ( & mut buffer , & env . ctx ) . unwrap ( ) . map ( | p | p . 0 ) . unwrap_or ( 0 ) ; env . garbage . lock ( ) . unwrap ( ) . extend ( buffer . garbage . drain ( .. ) ) ; r } ; Function :: new_native_with_env ( & self . store , env , wrapped ) } else { let wrapped = move | env : & Env < C > | { let mut buffer = env . message_buffer ( ) ; value . call_without_input ( & mut buffer , & env . ctx ) . unwrap ( ) ; env . garbage . lock ( ) . unwrap ( ) . extend ( buffer . garbage . drain ( .. ) ) ; } ; Function :: new_native_with_env ( & self . store , env , wrapped ) } ; self . import ( name , f ) } }
Import a function defined in the host into the guest.
Import a function defined in the host into the guest .
self
name
impl ToString
ctx
C
value
F