wasmer_vm/
function_env.rs

1use std::any::Any;
2
3/// Underlying FunctionEnvironment used by a `VMFunction`.
4pub struct VMFunctionEnvironment {
5    /// The contents of the environment.
6    pub contents: Box<dyn Any + Send + 'static>,
7}
8
9impl std::fmt::Debug for VMFunctionEnvironment {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        f.debug_struct("VMFunctionEnvironment")
12            .field("contents", &(&*self.contents as *const _))
13            .finish()
14    }
15}
16
17impl VMFunctionEnvironment {
18    /// Wraps the given value to expose it to Wasm code as a function context.
19    pub fn new(val: impl Any + Send + 'static) -> Self {
20        Self {
21            contents: Box::new(val),
22        }
23    }
24
25    #[allow(clippy::should_implement_trait)]
26    /// Returns a reference to the underlying value.
27    pub fn as_ref(&self) -> &(dyn Any + Send + 'static) {
28        &*self.contents
29    }
30
31    #[allow(clippy::should_implement_trait)]
32    /// Returns a mutable reference to the underlying value.
33    pub fn as_mut(&mut self) -> &mut (dyn Any + Send + 'static) {
34        &mut *self.contents
35    }
36}