pub struct ModuleWrapper { /* private fields */ }
Expand description

A wrapper type representing a runtime instance loaded with a single module

Implementations§

source§

impl ModuleWrapper

source

pub fn new_from_module( module: &Module, options: RuntimeOptions ) -> Result<Self, Error>

Creates a new ModuleWrapper from a given module and runtime options.

Arguments
  • module - A reference to the module to load.
  • options - The runtime options for the module.
Returns

A Result containing Self on success or an Error on failure.

source

pub fn new_from_file(path: &str, options: RuntimeOptions) -> Result<Self, Error>

Creates a new ModuleWrapper from a file path and runtime options.

Arguments
  • path - The path to the module file.
  • options - The runtime options for the module.
Returns

A Result containing Self on success or an Error on failure.

source

pub fn get_module_context(&self) -> &ModuleHandle

Returns a reference to the module context.

source

pub fn get_runtime(&mut self) -> &mut Runtime

Returns a mutable reference to the underlying runtime.

source

pub fn get<T>(&mut self, name: &str) -> Result<T, Error>where T: DeserializeOwned,

Retrieves a value from the module by name and deserializes it.

Arguments
  • name - The name of the value to retrieve.
Returns

A Result containing the deserialized value of type T on success or an Error on failure.

source

pub fn is_callable(&mut self, name: &str) -> bool

Checks if a value in the module with the given name is callable as a JavaScript function.

Arguments
  • name - The name of the value to check for callability.
Returns

true if the value is callable as a JavaScript function, false otherwise.

source

pub fn call<T>(&mut self, name: &str, args: &[Value]) -> Result<T, Error>where T: DeserializeOwned,

Calls a function in the module with the given name and arguments and deserializes the result.

Arguments
  • name - The name of the function to call.
  • args - The arguments to pass to the function.
Returns

A Result containing the deserialized result of type T on success or an Error on failure.

source

pub fn call_stored<T>( &mut self, function: &JsFunction<'_>, args: &[Value] ) -> Result<T, Error>where T: DeserializeOwned,

Calls a function using the module’s runtime that was previously stored as a JsFunction object

Arguments
  • function - The JsFunction to call.
  • args - The arguments to pass to the function.
Returns

A Result containing the deserialized result of type T on success or an Error on failure.

source

pub fn keys(&mut self) -> Vec<String>

Retrieves the names of the module’s exports.

Returns

A Vec of String containing the names of the keys.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> Send for Twhere T: ?Sized,

§

impl<T> Sync for Twhere T: ?Sized,