linera_wasmer_vm/
function_env.rs

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