wasmer_vm/
function_env.rs

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