ScriptEngine

Struct ScriptEngine 

Source
pub struct ScriptEngine;
Expand description

The global script engine

For rust and JavaScript interop.

Implementations§

Source§

impl ScriptEngine

Source

pub fn load_file(path: &str)

Load and run script file

To load from resource, use “:/” prefix, Example: load_file(“:/entry.js”)

Source

pub fn call_global_function(name: &str, args: &[ScriptValue]) -> ScriptValue

Call JavaScript function

See also: make_args, ScriptValue

Source

pub fn add_global_function<R, Fun, Args>(name: &str, func: Fun)
where Fun: ScriptFunction<R, Args> + 'static,

Export Rust function to JavaScript

Source

pub fn remove_global_function(name: &str)

Undo export of Rust function

Source

pub fn add_event_listener<R, Fun, Args>( event: &str, func: Fun, ) -> ScriptEventHandler
where R: IntoScriptValue, Fun: ScriptFunction<R, Args> + 'static,

Add an event listener callback Rust function

Source

pub fn remove_event_listener(handler: &mut ScriptEventHandler)

Remove an event listener callback Rust function

Source

pub fn post_event0(event: &str)

Trigger an event, both JavaScript and Rust event listeners will be notified.

Source

pub fn post_event1(event: &str, data: impl IntoScriptValue)

Trigger an event with data, both JavaScript and Rust event listeners will be notified.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.