emscripten_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_i32(i: i32) -> Self

Generate a Val object from an i32

source

pub fn from_u32(i: u32) -> Self

Generate a Val object from an u32

source

pub fn from_f32(i: f32) -> Self

Generate a Val object from an f32

source

pub fn from_f64(i: f64) -> Self

Generate a Val object from an f64

source

pub fn from_bool(i: bool) -> Self

Generate a Val object from a bool

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 as_f64(&self) -> f64

Converts current value to an f64

source

pub fn as_f32(&self) -> f32

Converts current value to an f32

source

pub fn as_i32(&self) -> i32

Converts current value to an i32

source

pub fn as_u32(&self) -> u32

Converts current value to a u32

source

pub fn as_bool(&self) -> bool

Converts current value to a bool. This can be useful also to check if a returned object is valid

source

pub fn as_string(&self) -> String

Converts current value to a string

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 to_vec<T: Clone + From<Val>>(&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 copy of the value. Read more
1.6.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<Val> for String

source§

fn from(item: Val) -> Self

Converts to this type from the input type.
source§

impl From<Val> for bool

source§

fn from(item: Val) -> Self

Converts to this type from the input type.
source§

impl From<Val> for f32

source§

fn from(item: Val) -> Self

Converts to this type from the input type.
source§

impl From<Val> for f64

source§

fn from(item: Val) -> Self

Converts to this type from the input type.
source§

impl From<Val> for i32

source§

fn from(item: Val) -> Self

Converts to this type from the input type.
source§

impl From<Val> for u32

source§

fn from(item: Val) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Val

source§

fn from(item: bool) -> Self

Converts to this type from the input type.
source§

impl From<f32> for Val

source§

fn from(item: f32) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Val

source§

fn from(item: f64) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Val

source§

fn from(item: i32) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Val

source§

fn from(item: u32) -> 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.6.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.6.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.6.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.6.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.6.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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.