Struct JsValue
pub struct JsValue { /* private fields */ }
Representation of an object owned by JS.
A JsValue doesn't actually live in Rust right now but actually in a table
owned by the wasm-bindgen generated JS glue code. Eventually the ownership
will transfer into Wasm directly and this will likely become more efficient,
but for now it may be slightly slow.
Implementations
impl JsValue
const NULL: JsValue = _;The
nullJS value constant.const UNDEFINED: JsValue = _;The
undefinedJS value constant.const TRUE: JsValue = _;The
trueJS value constant.const FALSE: JsValue = _;The
falseJS value constant.fn from_str(s: &str) -> JsValueCreates a new JS value which is a string.
The utf-8 string provided is copied to the JS heap and the string will be owned by the JS garbage collector.
fn from_f64(n: f64) -> JsValueCreates a new JS value which is a number.
This function creates a JS value representing a number (a heap allocated number) and returns a handle to the JS version of it.
fn bigint_from_str(s: &str) -> JsValueCreates a new JS value which is a bigint from a string representing a number.
This function creates a JS value representing a bigint (a heap allocated large integer) and returns a handle to the JS version of it.
const fn from_bool(b: bool) -> JsValueCreates a new JS value which is a boolean.
This function creates a JS object representing a boolean (a heap allocated boolean) and returns a handle to the JS version of it.
const fn undefined() -> JsValueCreates a new JS value representing
undefined.const fn null() -> JsValueCreates a new JS value representing
null.fn symbol(description: Option<&str>) -> JsValueCreates a new JS symbol with the optional description specified.
This function will invoke the
Symbolconstructor in JS and return the JS object corresponding to the symbol created.fn as_f64(&self) -> Option<f64>Returns the
f64value of this JS value if it's an instance of a number.If this JS value is not an instance of a number then this returns
None.fn is_string(&self) -> boolTests whether this JS value is a JS string.
fn as_string(&self) -> Option<String>If this JS value is a string value, this function copies the JS string value into Wasm linear memory, encoded as UTF-8, and returns it as a Rust
String.To avoid the copying and re-encoding, consider the
JsString::try_from()function from js-sys instead.If this JS value is not an instance of a string or if it's not valid utf-8 then this returns
None.UTF-16 vs UTF-8
JavaScript strings in general are encoded as UTF-16, but Rust strings are encoded as UTF-8. This can cause the Rust string to look a bit different than the JS string sometimes. For more details see the documentation about the
strtype which contains a few caveats about the encodings.fn as_bool(&self) -> Option<bool>Returns the
boolvalue of this JS value if it's an instance of a boolean.If this JS value is not an instance of a boolean then this returns
None.fn is_null(&self) -> boolTests whether this JS value is
nullfn is_undefined(&self) -> boolTests whether this JS value is
undefinedfn is_null_or_undefined(&self) -> boolTests whether this JS value is
nullorundefinedfn is_symbol(&self) -> boolTests whether the type of this JS value is
symbolfn is_object(&self) -> boolTests whether
typeof self == "object" && self !== null.fn is_array(&self) -> boolTests whether this JS value is an instance of Array.
fn is_function(&self) -> boolTests whether the type of this JS value is
function.fn is_bigint(&self) -> boolTests whether the type of this JS value is
bigint.fn js_typeof(&self) -> JsValueApplies the unary
typeofJS operator on aJsValue.fn js_in(&self, obj: &JsValue) -> boolApplies the binary
inJS operator on the twoJsValues.fn is_truthy(&self) -> boolTests whether the value is "truthy".
fn is_falsy(&self) -> boolTests whether the value is "falsy".
fn loose_eq(&self, other: &Self) -> boolCompare two
JsValues for equality, using the==operator in JS.fn bit_not(&self) -> JsValueApplies the unary
~JS operator on aJsValue.fn unsigned_shr(&self, rhs: &Self) -> u32Applies the binary
>>>JS operator on the twoJsValues.fn checked_div(&self, rhs: &Self) -> SelfApplies the binary
/JS operator on twoJsValues, catching and returning anyRangeErrorthrown.fn pow(&self, rhs: &Self) -> SelfApplies the binary
**JS operator on the twoJsValues.fn lt(&self, other: &Self) -> boolApplies the binary
<JS operator on the twoJsValues.fn le(&self, other: &Self) -> boolApplies the binary
<=JS operator on the twoJsValues.fn ge(&self, other: &Self) -> boolApplies the binary
>=JS operator on the twoJsValues.fn gt(&self, other: &Self) -> boolApplies the binary
>JS operator on the twoJsValues.fn unchecked_into_f64(&self) -> f64Applies the unary
+JS operator on aJsValue. Can throw.
Trait Implementations
impl Add for JsValue
type Output = <&'static JsValue as Add>::Output;fn add(self, other: JsValue) -> <&'static JsValue as Add<&'static JsValue>>::Output
impl Add<&JsValue> for JsValue
type Output = <&'static JsValue as Add>::Output;fn add(self, other: &JsValue) -> <&'static JsValue as Add<&'static JsValue>>::Output
impl AsRef<JsValue> for JsValue
fn as_ref(&self) -> &JsValue
impl BitAnd for JsValue
type Output = <&'static JsValue as BitAnd>::Output;fn bitand(self, other: JsValue) -> <&'static JsValue as BitAnd<&'static JsValue>>::Output
impl BitAnd<&JsValue> for JsValue
type Output = <&'static JsValue as BitAnd>::Output;fn bitand(self, other: &JsValue) -> <&'static JsValue as BitAnd<&'static JsValue>>::Output
impl BitOr for JsValue
type Output = <&'static JsValue as BitOr>::Output;fn bitor(self, other: JsValue) -> <&'static JsValue as BitOr<&'static JsValue>>::Output
impl BitOr<&JsValue> for JsValue
type Output = <&'static JsValue as BitOr>::Output;fn bitor(self, other: &JsValue) -> <&'static JsValue as BitOr<&'static JsValue>>::Output
impl BitXor for JsValue
type Output = <&'static JsValue as BitXor>::Output;fn bitxor(self, other: JsValue) -> <&'static JsValue as BitXor<&'static JsValue>>::Output
impl BitXor<&JsValue> for JsValue
type Output = <&'static JsValue as BitXor>::Output;fn bitxor(self, other: &JsValue) -> <&'static JsValue as BitXor<&'static JsValue>>::Output
impl Clone for JsValue
fn clone(&self) -> JsValue
impl Debug for JsValue
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for JsValue
fn default() -> Self
impl Div for JsValue
type Output = <&'static JsValue as Div>::Output;fn div(self, other: JsValue) -> <&'static JsValue as Div<&'static JsValue>>::Output
impl Div<&JsValue> for JsValue
type Output = <&'static JsValue as Div>::Output;fn div(self, other: &JsValue) -> <&'static JsValue as Div<&'static JsValue>>::Output
impl Drop for JsValue
fn drop(&mut self)
impl From<JsError> for JsValue
fn from(error: JsError) -> Self
impl From<Null> for JsValue
fn from(obj: Null) -> JsValue
impl From<String> for JsValue
fn from(s: String) -> JsValue
impl From<Undefined> for JsValue
fn from(obj: Undefined) -> JsValue
impl From<bool> for JsValue
fn from(s: bool) -> JsValue
impl From<f32> for JsValue
fn from(n: f32) -> JsValue
impl From<f64> for JsValue
fn from(n: f64) -> JsValue
impl From<i128> for JsValue
fn from(arg: i128) -> JsValue
impl From<i16> for JsValue
fn from(n: i16) -> JsValue
impl From<i32> for JsValue
fn from(n: i32) -> JsValue
impl From<i64> for JsValue
fn from(arg: i64) -> JsValue
impl From<i8> for JsValue
fn from(n: i8) -> JsValue
impl From<isize> for JsValue
fn from(n: isize) -> Self
impl From<u128> for JsValue
fn from(arg: u128) -> JsValue
impl From<u16> for JsValue
fn from(n: u16) -> JsValue
impl From<u32> for JsValue
fn from(n: u32) -> JsValue
impl From<u64> for JsValue
fn from(arg: u64) -> JsValue
impl From<u8> for JsValue
fn from(n: u8) -> JsValue
impl From<usize> for JsValue
fn from(n: usize) -> Self
impl FromWasmAbi for JsValue
type Abi = u32;unsafe fn from_abi(js: u32) -> JsValue
impl IntoJsGeneric for JsValue
type JsCanon = JsValue;fn to_js(self) -> JsValue
impl IntoWasmAbi for JsValue
type Abi = u32;fn into_abi(self) -> u32
impl JsCast for JsValue
fn instanceof(_val: &JsValue) -> boolfn unchecked_from_js(val: JsValue) -> Selffn unchecked_from_js_ref(val: &JsValue) -> &Self
impl LongRefFromWasmAbi for JsValue
type Abi = u32;type Anchor = JsValue;unsafe fn long_ref_from_abi(js: u32) -> Self::Anchor
impl Mul for JsValue
type Output = <&'static JsValue as Mul>::Output;fn mul(self, other: JsValue) -> <&'static JsValue as Mul<&'static JsValue>>::Output
impl Mul<&JsValue> for JsValue
type Output = <&'static JsValue as Mul>::Output;fn mul(self, other: &JsValue) -> <&'static JsValue as Mul<&'static JsValue>>::Output
impl Neg for JsValue
type Output = <&'static JsValue as Neg>::Output;fn neg(self) -> <&'static JsValue as Neg>::Output
impl Not for JsValue
type Output = <&'static JsValue as Not>::Output;fn not(self) -> <&'static JsValue as Not>::Output
impl OptionFromWasmAbi for JsValue
fn is_none(js: &u32) -> bool
impl OptionIntoWasmAbi for JsValue
fn none() -> u32
impl PartialEq for JsValue
fn eq(&self, other: &Self) -> boolCompares two
JsValues for equality, using the===operator in JS.
impl PartialEq<String> for JsValue
fn eq(&self, other: &String) -> bool
impl PartialEq<bool> for JsValue
fn eq(&self, other: &bool) -> bool
impl PartialEq<f32> for JsValue
fn eq(&self, other: &f32) -> bool
impl PartialEq<f64> for JsValue
fn eq(&self, other: &f64) -> bool
impl PartialEq<i128> for JsValue
fn eq(&self, other: &i128) -> bool
impl PartialEq<i16> for JsValue
fn eq(&self, other: &i16) -> bool
impl PartialEq<i32> for JsValue
fn eq(&self, other: &i32) -> bool
impl PartialEq<i64> for JsValue
fn eq(&self, other: &i64) -> bool
impl PartialEq<i8> for JsValue
fn eq(&self, other: &i8) -> bool
impl PartialEq<isize> for JsValue
fn eq(&self, other: &isize) -> bool
impl PartialEq<str> for JsValue
fn eq(&self, other: &str) -> bool
impl PartialEq<u128> for JsValue
fn eq(&self, other: &u128) -> bool
impl PartialEq<u16> for JsValue
fn eq(&self, other: &u16) -> bool
impl PartialEq<u32> for JsValue
fn eq(&self, other: &u32) -> bool
impl PartialEq<u64> for JsValue
fn eq(&self, other: &u64) -> bool
impl PartialEq<u8> for JsValue
fn eq(&self, other: &u8) -> bool
impl PartialEq<usize> for JsValue
fn eq(&self, other: &usize) -> bool
impl Promising for JsValue
type Resolution = JsValue;
impl RefFromWasmAbi for JsValue
type Abi = u32;type Anchor = ManuallyDrop<JsValue>;unsafe fn ref_from_abi(js: u32) -> Self::Anchor
impl Rem for JsValue
type Output = <&'static JsValue as Rem>::Output;fn rem(self, other: JsValue) -> <&'static JsValue as Rem<&'static JsValue>>::Output
impl Rem<&JsValue> for JsValue
type Output = <&'static JsValue as Rem>::Output;fn rem(self, other: &JsValue) -> <&'static JsValue as Rem<&'static JsValue>>::Output
impl Send for JsValue
impl Shl for JsValue
type Output = <&'static JsValue as Shl>::Output;fn shl(self, other: JsValue) -> <&'static JsValue as Shl<&'static JsValue>>::Output
impl Shl<&JsValue> for JsValue
type Output = <&'static JsValue as Shl>::Output;fn shl(self, other: &JsValue) -> <&'static JsValue as Shl<&'static JsValue>>::Output
impl Shr for JsValue
type Output = <&'static JsValue as Shr>::Output;fn shr(self, other: JsValue) -> <&'static JsValue as Shr<&'static JsValue>>::Output
impl Shr<&JsValue> for JsValue
type Output = <&'static JsValue as Shr>::Output;fn shr(self, other: &JsValue) -> <&'static JsValue as Shr<&'static JsValue>>::Output
impl Sub for JsValue
type Output = <&'static JsValue as Sub>::Output;fn sub(self, other: JsValue) -> <&'static JsValue as Sub<&'static JsValue>>::Output
impl Sub<&JsValue> for JsValue
type Output = <&'static JsValue as Sub>::Output;fn sub(self, other: &JsValue) -> <&'static JsValue as Sub<&'static JsValue>>::Output
impl Sync for JsValue
impl UpcastFrom<()> for JsValue
impl UpcastFrom<JsError> for JsValue
impl UpcastFrom<JsValue> for JsValue
impl UpcastFrom<Null> for JsValue
impl UpcastFrom<Undefined> for JsValue
impl UpcastFrom<bool> for JsValue
impl UpcastFrom<char> for JsValue
impl UpcastFrom<f32> for JsValue
impl UpcastFrom<f64> for JsValue
impl UpcastFrom<i128> for JsValue
impl UpcastFrom<i16> for JsValue
impl UpcastFrom<i32> for JsValue
impl UpcastFrom<i64> for JsValue
impl UpcastFrom<i8> for JsValue
impl UpcastFrom<isize> for JsValue
impl UpcastFrom<u128> for JsValue
impl UpcastFrom<u16> for JsValue
impl UpcastFrom<u32> for JsValue
impl UpcastFrom<u64> for JsValue
impl UpcastFrom<u8> for JsValue
impl UpcastFrom<usize> for JsValue
impl<'a> From<&'a String> for JsValue
fn from(s: &'a String) -> JsValue
impl<'a> From<&'a str> for JsValue
fn from(s: &'a str) -> JsValue
impl<'a> PartialEq<&'a String> for JsValue
fn eq(&self, other: &&'a String) -> bool
impl<'a> PartialEq<&'a str> for JsValue
fn eq(&self, other: &&'a str) -> bool
impl<'a, T> From<&'a T> for JsValue
where
T: JsCast,
fn from(s: &'a T) -> JsValue
impl<T> From<*const T> for JsValue
fn from(s: *const T) -> JsValue
impl<T> From<*mut T> for JsValue
fn from(s: *mut T) -> JsValue
impl<T> From<JsNullable<T>> for JsValue
fn from(obj: JsNullable<T>) -> JsValue
impl<T> From<JsOption<T>> for JsValue
fn from(obj: JsOption<T>) -> JsValue
impl<T> From<NonNull<T>> for JsValue
fn from(s: NonNull<T>) -> JsValue
impl<T> From<Option<T>> for JsValue
where
JsValue: From<T>,
fn from(s: Option<T>) -> JsValue
impl<T> UpcastFrom<JsNullable<T>> for JsValue
impl<T> UpcastFrom<JsOption<T>> for JsValue
impl<T: VectorIntoWasmAbi> From<Box<[T]>> for JsValue
fn from(vector: Box<[T]>) -> Self
impl<T: VectorIntoWasmAbi> From<Clamped<Box<[T]>>> for JsValue
fn from(vector: Clamped<Box<[T]>>) -> Self
impl<T: VectorIntoWasmAbi> From<Clamped<Vec<T>>> for JsValue
fn from(vector: Clamped<Vec<T>>) -> Self
impl<T: VectorIntoWasmAbi> From<Vec<T>> for JsValue
fn from(vector: Vec<T>) -> Self