wasmer-vm 3.2.0-alpha.1

Runtime library support for Wasmer
Documentation
use derivative::Derivative;
use std::any::Any;

/// Underlying FunctionEnvironment used by a `VMFunction`.
#[derive(Derivative)]
#[derivative(Debug)]
pub struct VMFunctionEnvironment {
    #[derivative(Debug = "ignore")]
    contents: Box<dyn Any + Send + 'static>,
}

impl VMFunctionEnvironment {
    /// Wraps the given value to expose it to Wasm code as a function context.
    pub fn new(val: impl Any + Send + 'static) -> Self {
        Self {
            contents: Box::new(val),
        }
    }

    #[allow(clippy::should_implement_trait)]
    /// Returns a reference to the underlying value.
    pub fn as_ref(&self) -> &(dyn Any + Send + 'static) {
        &*self.contents
    }

    #[allow(clippy::should_implement_trait)]
    /// Returns a mutable reference to the underlying value.
    pub fn as_mut(&mut self) -> &mut (dyn Any + Send + 'static) {
        &mut *self.contents
    }
}