Struct MiniV8

Source
pub struct MiniV8 { /* private fields */ }

Implementations§

Source§

impl MiniV8

Source

pub fn new() -> MiniV8

Source

pub fn global(&self) -> Object

Returns the global JavaScript object.

Source

pub fn eval<S, R>(&self, script: S) -> Result<R>
where S: Into<Script>, R: FromValue,

Executes a JavaScript script and returns its result.

Source

pub fn set_user_data<K, T>(&self, key: K, data: T) -> Option<Box<dyn Any>>
where K: ToString, T: Any,

Inserts any sort of keyed value of type T into the MiniV8, typically for later retrieval from within Rust functions called from within JavaScript. If a value already exists with the key, it is returned.

Source

pub fn use_user_data<F, T: Any, U>(&self, key: &str, func: F) -> U
where F: FnOnce(Option<&T>) -> U + 'static,

Calls a function with a user data value by its key, or None if no value exists with the key. If a value exists but it is not of the type T, None is returned. This is typically used by a Rust function called from within JavaScript.

Source

pub fn remove_user_data(&self, key: &str) -> Option<Box<dyn Any>>

Removes and returns a user data value by its key. Returns None if no value exists with the key.

Source

pub fn create_string(&self, value: &str) -> String

Creates and returns a string managed by V8.

§Panics

Panics if source value is longer than (1 << 28) - 16 bytes.

Source

pub fn create_array(&self) -> Array

Creates and returns an empty Array managed by V8.

Source

pub fn create_object(&self) -> Object

Creates and returns an empty Object managed by V8.

Source

pub fn create_object_from<K, V, I>(&self, iter: I) -> Result<Object>
where K: ToValue, V: ToValue, I: IntoIterator<Item = (K, V)>,

Creates and returns an Object managed by V8 filled with the keys and values from an iterator. Keys are coerced to object properties.

This is a thin wrapper around MiniV8::create_object and Object::set. See Object::set for how this method might return an error.

Source

pub fn create_function<F, R>(&self, func: F) -> Function
where F: Fn(Invocation) -> Result<R> + 'static, R: ToValue,

Wraps a Rust function or closure, creating a callable JavaScript function handle to it.

The function’s return value is always a Result: If the function returns Err, the error is raised as a JavaScript exception, which can be caught within JavaScript or bubbled up back into Rust by not catching it. This allows using the ? operator to propagate errors through intermediate JavaScript code.

If the function returns Ok, the contained value will be converted to a JavaScript value. For details on Rust-to-JavaScript conversions, refer to the ToValue and ToValues traits.

If the provided function panics, the executable will be aborted.

Source

pub fn create_function_mut<F, R>(&self, func: F) -> Function
where F: FnMut(Invocation) -> Result<R> + 'static, R: ToValue,

Wraps a mutable Rust closure, creating a callable JavaScript function handle to it.

This is a version of create_function that accepts a FnMut argument. Refer to create_function for more information about the implementation.

Trait Implementations§

Source§

impl Clone for MiniV8

Source§

fn clone(&self) -> MiniV8

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for MiniV8

§

impl !RefUnwindSafe for MiniV8

§

impl !Send for MiniV8

§

impl !Sync for MiniV8

§

impl Unpin for MiniV8

§

impl !UnwindSafe for MiniV8

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.