Skip to main content

JsValue

Enum JsValue 

Source
pub enum JsValue {
    Undefined,
    Null,
    Bool(bool),
    Number(f64),
    String(String),
    BigInt(JsBigInt),
    Array(Rc<RefCell<Vec<JsValue>>>),
    Object(Rc<RefCell<BTreeMap<String, JsValue>>>),
    Function(ClosureHandle),
    Symbol(SymbolId),
    Promise(JsPromise<JsValue>),
}
Expand description

Tagged union representing dynamic JavaScript values with authentic ECMAScript reference semantics.

Variants§

§

Undefined

§

Null

§

Bool(bool)

§

Number(f64)

§

String(String)

§

BigInt(JsBigInt)

§

Array(Rc<RefCell<Vec<JsValue>>>)

§

Object(Rc<RefCell<BTreeMap<String, JsValue>>>)

§

Function(ClosureHandle)

§

Symbol(SymbolId)

§

Promise(JsPromise<JsValue>)

Implementations§

Source§

impl JsValue

Source

pub fn from_json_str(s: &str) -> Result<JsValue, String>

Parses a JSON string into a JsValue.

Source

pub fn to_json_string(&self) -> String

Serializes this JsValue into a standard JSON string.

Source

pub fn try_to_json_string(&self) -> Result<String, String>

Serializes this JsValue into a standard JSON string, returning an error if a cycle is detected.

Source

pub fn js_typeof(&self) -> &'static str

Returns JavaScript typeof string for this value.

Source

pub fn strict_eq(&self, other: &JsValue) -> bool

Strict equality comparison (===) adhering to ECMAScript standard.

Source

pub fn loose_eq(&self, other: &JsValue) -> bool

Abstract loose equality comparison (==) adhering to ECMAScript standard.

Source

pub fn is_null(&self) -> bool

Source

pub fn is_undefined(&self) -> bool

Source

pub fn is_truthy(&self) -> bool

Source

pub fn is_function(&self) -> bool

Source

pub fn is_symbol(&self) -> bool

Source

pub fn is_promise(&self) -> bool

Source

pub fn as_promise(&self) -> Option<&JsPromise<JsValue>>

Source

pub fn new_promise(p: JsPromise<JsValue>) -> JsValue

Source

pub fn new_object(map: BTreeMap<String, JsValue>) -> JsValue

Source

pub fn new_array(items: Vec<JsValue>) -> JsValue

Source

pub fn empty_object() -> JsValue

Source

pub fn empty_array() -> JsValue

Source

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

Source

pub fn get_prop(&self, key: &str) -> Option<JsValue>

Source

pub fn set_prop(&self, key: impl Into<String>, val: impl Into<JsValue>) -> bool

Source

pub fn get_property(&self, key: &str) -> Option<JsValue>

Source

pub fn set_property( &self, key: impl Into<String>, val: impl Into<JsValue>, ) -> bool

Source

pub fn as_closure_handle(&self) -> Option<&ClosureHandle>

Source

pub fn as_symbol(&self) -> Option<&SymbolId>

Source

pub fn as_f64(&self) -> Option<f64>

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn as_bool(&self) -> Option<bool>

Source

pub fn as_bigint(&self) -> Option<&JsBigInt>

Source

pub fn remove_property(&mut self, key: &str) -> Option<JsValue>

Source

pub fn get_index(&self, index: usize) -> Option<JsValue>

Source

pub fn set_index(&mut self, index: usize, val: impl Into<JsValue>)

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn map<F>(&self, f: F) -> JsValue
where F: FnMut(&JsValue) -> JsValue,

Source

pub fn filter<F>(&self, f: F) -> JsValue
where F: FnMut(&JsValue) -> bool,

Source

pub fn reduce<F>(&self, f: F, initial: JsValue) -> JsValue
where F: FnMut(JsValue, &JsValue) -> JsValue,

Source

pub fn find<F>(&self, f: F) -> Option<JsValue>
where F: Fn(&JsValue) -> bool,

Source

pub fn find_index<F>(&self, f: F) -> Option<usize>
where F: Fn(&JsValue) -> bool,

Source

pub fn some<F>(&self, f: F) -> bool
where F: Fn(&JsValue) -> bool,

Source

pub fn every<F>(&self, f: F) -> bool
where F: Fn(&JsValue) -> bool,

Source

pub fn includes(&self, item: &JsValue) -> bool

Source

pub fn slice(&self, start: isize, end: Option<isize>) -> JsValue

Source

pub fn join(&self, separator: &str) -> String

Source

pub fn push(&mut self, val: impl Into<JsValue>)

Source

pub fn pop(&mut self) -> Option<JsValue>

Source

pub fn concat(&self, other: &JsValue) -> JsValue

Source

pub fn reverse(&mut self)

Source

pub fn sort_by<F>(&mut self, f: F)
where F: FnMut(&JsValue, &JsValue) -> Ordering,

Source

pub fn flat(&self, depth: usize) -> JsValue

Trait Implementations§

Source§

impl Clone for JsValue

Source§

fn clone(&self) -> JsValue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for JsValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for JsValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<&String> for JsValue

Source§

fn from(v: &String) -> JsValue

Converts to this type from the input type.
Source§

impl From<&str> for JsValue

Source§

fn from(v: &str) -> JsValue

Converts to this type from the input type.
Source§

impl From<BTreeMap<String, JsValue>> for JsValue

Source§

fn from(v: BTreeMap<String, JsValue>) -> JsValue

Converts to this type from the input type.
Source§

impl From<JsBigInt> for JsValue

Source§

fn from(v: JsBigInt) -> JsValue

Converts to this type from the input type.
Source§

impl From<JsPromise<JsValue>> for JsValue

Source§

fn from(p: JsPromise<JsValue>) -> JsValue

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for JsValue
where T: Into<JsValue>,

Source§

fn from(opt: Option<T>) -> JsValue

Converts to this type from the input type.
Source§

impl From<String> for JsValue

Source§

fn from(v: String) -> JsValue

Converts to this type from the input type.
Source§

impl From<Vec<JsValue>> for JsValue

Source§

fn from(v: Vec<JsValue>) -> JsValue

Converts to this type from the input type.
Source§

impl From<bool> for JsValue

Source§

fn from(v: bool) -> JsValue

Converts to this type from the input type.
Source§

impl From<f32> for JsValue

Source§

fn from(v: f32) -> JsValue

Converts to this type from the input type.
Source§

impl From<f64> for JsValue

Source§

fn from(v: f64) -> JsValue

Converts to this type from the input type.
Source§

impl From<i32> for JsValue

Source§

fn from(v: i32) -> JsValue

Converts to this type from the input type.
Source§

impl From<i64> for JsValue

Source§

fn from(v: i64) -> JsValue

Converts to this type from the input type.
Source§

impl From<isize> for JsValue

Source§

fn from(v: isize) -> JsValue

Converts to this type from the input type.
Source§

impl From<u32> for JsValue

Source§

fn from(v: u32) -> JsValue

Converts to this type from the input type.
Source§

impl From<u64> for JsValue

Source§

fn from(v: u64) -> JsValue

Converts to this type from the input type.
Source§

impl From<usize> for JsValue

Source§

fn from(v: usize) -> JsValue

Converts to this type from the input type.
Source§

impl Index<&str> for JsValue

Source§

type Output = JsValue

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &<JsValue as Index<&str>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for JsValue

Source§

type Output = JsValue

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &<JsValue as Index<usize>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for JsValue

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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> 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoInitialState<T> for T

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>