Val

Struct Val 

Source
#[repr(C)]
pub struct Val { /* private fields */ }
Expand description

Val is a wrapper around emscripten’s EM_VAL type, which itself represents javascript objects

Implementations§

Source§

impl Val

Source

pub fn global(name: &str) -> Self

Looks up a global value represented by name

Source

pub fn take_ownership(v: EM_VAL) -> Self

Creates a Val from a raw handle. This can be used for retrieving values from JavaScript, where the JavaScript side should wrap a value with Emval.toHandle, pass it to Rust, and then Rust can use take_ownership to convert it to a Val instance

Source

pub fn from_val(v: &Val) -> Self

Create a Val from another Val instance

Source

pub fn undefined() -> Self

Create a Val that represents undefined

Source

pub fn object() -> Self

Creates a new Object

Source

pub fn null() -> Self

Create a Val that represents null

Source

pub fn array() -> Self

Creates and returns a new Array

Source

pub fn from_str(s: &str) -> Self

Creates a Val from a string slice

Source

pub fn module_property(s: &str) -> Self

Looks up a value by the provided name on the Emscripten Module object.

Source

pub fn from_array<T: Clone + Into<Val>>(arr: &[T]) -> Self

Creates a Val from an array

Source

pub fn as_handle(&self) -> EM_VAL

Get the EM_VAL handle of a Val object

Source

pub fn call(&self, f: &str, args: &[&Val]) -> Val

Call a method associated with the JS object represented by the Val object

Source

pub fn get<T: Clone + Into<Val>>(&self, prop: &T) -> Val

Get a property

Source

pub fn set<T: Clone + Into<Val>, U: Clone + Into<Val>>(&self, prop: &T, val: &U)

Set a property

Source

pub fn from_<T: JsType>(v: T) -> Self

Generate a Val object from a type implementing JsType

Source

pub fn as_<T: JsType>(&self) -> T

Generate a Val object from a type implementing JsType

Source

pub fn as_i32(&self) -> i32

Generate a Val object from a type implementing JsType

Source

pub fn release_ownership(&mut self) -> EM_VAL

Get and release ownership of the internal handle

Source

pub fn has_own_property(&self, key: &str) -> bool

Checks if the JavaScript object has own (non-inherited) property with the specified name.

Source

pub fn is_null(&self) -> bool

Checks whether a value is null

Source

pub fn is_undefined(&self) -> bool

Checks whether a value is undefined

Source

pub fn is_true(&self) -> bool

Checks whether a value is true

Source

pub fn is_false(&self) -> bool

Checks whether a value is false

Source

pub fn is_number(&self) -> bool

Checks whether a value is a number

Source

pub fn is_string(&self) -> bool

Checks whether a value is a string

Source

pub fn instanceof(&self, v: &Val) -> bool

Checks whether the object is an instanceof another object

Source

pub fn is_array(&self) -> bool

Checks whether a value is an Array

Source

pub fn is_in(&self, v: &Val) -> bool

Checks if the specified property is in the specified object

Source

pub fn type_of(&self) -> Val

Returns the typeof the object

Source

pub fn throw(&self) -> bool

Throw the object as a JS exception

Source

pub fn await_(&self) -> Val

Pauses the Rust code to await the Promise / thenable. This requires ASYNCIFY to be enabled

Source

pub fn delete<T: Clone + Into<Val>>(&self, prop: &T) -> bool

Removes a property from an object

Source

pub fn new(&self, args: &[&Val]) -> Val

Instantiate a new object, passes the args to the object’s contructor

Source

pub fn strictly_equals<T: Clone + Into<Val>>(&self, v: &T) -> bool

Check if the current object is strictly equals to another object ===

Source

pub fn not(&self) -> bool

Checks the validity of an object

Source

pub fn add_event_listener<F: FnMut(&Val) -> Val + 'static>( &self, ev: &str, f: F, )

Convenience method. Adds a callback to an EventTarget object

Source

pub fn from_fn0<F: FnMut() -> Val + 'static>(f: F) -> Val

Generates a Val object from a function object which takes 0 args

Source

pub fn from_fn1<F: FnMut(&Val) -> Val + 'static>(f: F) -> Val

Generates a Val object from a function object which takes 1 arg

Source

pub fn from_fn2<F: FnMut(&Val, &Val) -> Val + 'static>(f: F) -> Val

Generates a Val object from a function object which takes 2 args

Source

pub fn from_fn3<F: FnMut(&Val, &Val, &Val) -> Val + 'static>(f: F) -> Val

Generates a Val object from a function object which takes 3 args

Source

pub fn from_fn4<F: FnMut(&Val, &Val, &Val, &Val) -> Val + 'static>(f: F) -> Val

Generates a Val object from a function object which takes 4 args

Source

pub fn as_string(&self) -> String

Converts current value to a string

Source

pub fn to_vec<T: JsType>(&self) -> Vec<T>

Convert a javascript Array to a Rust Vec

Trait Implementations§

Source§

impl Clone for Val

Source§

fn clone(&self) -> Self

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
Source§

impl Default for Val

Source§

fn default() -> Val

Returns the “default value” for a type. Read more
Source§

impl Drop for Val

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&Val> for Val

Source§

fn from(item: &Val) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Val

Source§

fn from(item: &str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Val

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Val

Source§

fn from(item: String) -> Self

Converts to this type from the input type.
Source§

impl<T: JsType> From<T> for Val

Source§

fn from(v: T) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Val

Source§

fn eq(&self, other: &Val) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Val

Source§

fn partial_cmp(&self, other: &Val) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Val

Auto Trait Implementations§

§

impl Freeze for Val

§

impl RefUnwindSafe for Val

§

impl !Send for Val

§

impl !Sync for Val

§

impl Unpin for Val

§

impl UnwindSafe for Val

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.