Struct rquickjs::Value

source ·
pub struct Value<'js> { /* private fields */ }
Expand description

Any JavaScript value

Implementations§

source§

impl<'js> Value<'js>

source

pub fn new_uninitialized(ctx: Ctx<'js>) -> Value<'js>

source

pub fn new_undefined(ctx: Ctx<'js>) -> Value<'js>

source

pub fn new_null(ctx: Ctx<'js>) -> Value<'js>

source

pub fn new_bool(ctx: Ctx<'js>, value: bool) -> Value<'js>

Create new boolean value

source

pub fn ctx(&self) -> &Ctx<'js>

Returns the Ctx object associated with this value.

source

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

Try get bool from value

source

pub fn new_int(ctx: Ctx<'js>, value: i32) -> Value<'js>

Create new int value

source

pub fn as_int(&self) -> Option<i32>

Try get int from value

source

pub fn new_float(ctx: Ctx<'js>, value: f64) -> Value<'js>

Create new float value

source

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

Try get float from value

source

pub fn new_number(ctx: Ctx<'js>, value: f64) -> Value<'js>

Create a new number value

source

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

Try get any number from value

source

pub fn is_null(&self) -> bool

Returns if the value is the JavaScript null value.

source

pub fn is_undefined(&self) -> bool

Returns if the value is the JavaScript undefined value.

source

pub fn is_bool(&self) -> bool

Check if the value is a bool

source

pub fn is_int(&self) -> bool

Check if the value is an int

source

pub fn is_float(&self) -> bool

Check if the value is a float

source

pub fn is_number(&self) -> bool

Check if the value is an any number

source

pub fn is_string(&self) -> bool

Check if the value is a string

source

pub fn is_symbol(&self) -> bool

Check if the value is a symbol

source

pub fn is_object(&self) -> bool

Check if the value is an object

source

pub fn is_module(&self) -> bool

Check if the value is a module

source

pub fn is_array(&self) -> bool

Check if the value is an array

source

pub fn is_function(&self) -> bool

Check if the value is a function

source

pub fn is_constructor(&self) -> bool

Check if the value is a constructor function

source

pub fn is_promise(&self) -> bool

Check if the value is a promise.

source

pub fn is_exception(&self) -> bool

Check if the value is an exception

source

pub fn is_error(&self) -> bool

Check if the value is an error

source

pub fn as_value(&self) -> &Value<'js>

Reference as value

source

pub fn get<T>(&self) -> Result<T, Error>
where T: FromJs<'js>,

Convert from value to specified type

source

pub fn as_raw(&self) -> JSValue

Returns the raw C library JavaScript value.

source

pub unsafe fn from_raw(ctx: Ctx<'js>, value: JSValue) -> Value<'js>

Create a value from the C library JavaScript value.

§Safety

The value cannot be from an unrelated runtime and the value must be owned. QuickJS JavaScript values are reference counted. The drop implementation of this type decrements the reference count so the value must have count which won’t be decremented elsewhere. Use qjs::JS_DupValue to increment the reference count of the value.

source§

impl<'js> Value<'js>

source

pub fn type_of(&self) -> Type

Get the type of value

source

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

Get the name of type

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_string(&self) -> &String<'js>

Interpret as String

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_string(&self) -> Option<&String<'js>>

Try reinterpret as String

source

pub fn into_string(self) -> Option<String<'js>>

Try convert into String

source

pub fn try_into_string(self) -> Result<String<'js>, Value<'js>>

Try convert into String returning self if the conversion fails.

source

pub fn from_string(value: String<'js>) -> Value<'js>

Convert from String

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_symbol(&self) -> &Symbol<'js>

Interpret as Symbol

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_symbol(&self) -> Option<&Symbol<'js>>

Try reinterpret as Symbol

source

pub fn into_symbol(self) -> Option<Symbol<'js>>

Try convert into Symbol

source

pub fn try_into_symbol(self) -> Result<Symbol<'js>, Value<'js>>

Try convert into Symbol returning self if the conversion fails.

source

pub fn from_symbol(value: Symbol<'js>) -> Value<'js>

Convert from Symbol

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_object(&self) -> &Object<'js>

Interpret as Object

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_object(&self) -> Option<&Object<'js>>

Try reinterpret as Object

source

pub fn into_object(self) -> Option<Object<'js>>

Try convert into Object

source

pub fn try_into_object(self) -> Result<Object<'js>, Value<'js>>

Try convert into Object returning self if the conversion fails.

source

pub fn from_object(value: Object<'js>) -> Value<'js>

Convert from Object

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_function(&self) -> &Function<'js>

Interpret as Function

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_function(&self) -> Option<&Function<'js>>

Try reinterpret as Function

source

pub fn into_function(self) -> Option<Function<'js>>

Try convert into Function

source

pub fn try_into_function(self) -> Result<Function<'js>, Value<'js>>

Try convert into Function returning self if the conversion fails.

source

pub fn from_function(value: Function<'js>) -> Value<'js>

Convert from Function

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_constructor(&self) -> &Constructor<'js>

Interpret as Constructor

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_constructor(&self) -> Option<&Constructor<'js>>

Try reinterpret as Constructor

source

pub fn into_constructor(self) -> Option<Constructor<'js>>

Try convert into Constructor

source

pub fn try_into_constructor(self) -> Result<Constructor<'js>, Value<'js>>

Try convert into Constructor returning self if the conversion fails.

source

pub fn from_constructor(value: Constructor<'js>) -> Value<'js>

Convert from Constructor

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_promise(&self) -> &Promise<'js>

Interpret as Promise

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_promise(&self) -> Option<&Promise<'js>>

Try reinterpret as Promise

source

pub fn into_promise(self) -> Option<Promise<'js>>

Try convert into Promise

source

pub fn try_into_promise(self) -> Result<Promise<'js>, Value<'js>>

Try convert into Promise returning self if the conversion fails.

source

pub fn from_promise(value: Promise<'js>) -> Value<'js>

Convert from Promise

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_array(&self) -> &Array<'js>

Interpret as Array

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_array(&self) -> Option<&Array<'js>>

Try reinterpret as Array

source

pub fn into_array(self) -> Option<Array<'js>>

Try convert into Array

source

pub fn try_into_array(self) -> Result<Array<'js>, Value<'js>>

Try convert into Array returning self if the conversion fails.

source

pub fn from_array(value: Array<'js>) -> Value<'js>

Convert from Array

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_exception(&self) -> &Exception<'js>

Interpret as Exception

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_exception(&self) -> Option<&Exception<'js>>

Try reinterpret as Exception

source

pub fn into_exception(self) -> Option<Exception<'js>>

Try convert into Exception

source

pub fn try_into_exception(self) -> Result<Exception<'js>, Value<'js>>

Try convert into Exception returning self if the conversion fails.

source

pub fn from_exception(value: Exception<'js>) -> Value<'js>

Convert from Exception

source§

impl<'js> Value<'js>

source

pub unsafe fn ref_big_int(&self) -> &BigInt<'js>

Interpret as BigInt

§Safety

You should be sure that the value already is of required type before to do it.

source

pub fn as_big_int(&self) -> Option<&BigInt<'js>>

Try reinterpret as BigInt

source

pub fn into_big_int(self) -> Option<BigInt<'js>>

Try convert into BigInt

source

pub fn try_into_big_int(self) -> Result<BigInt<'js>, Value<'js>>

Try convert into BigInt returning self if the conversion fails.

source

pub fn from_big_int(value: BigInt<'js>) -> Value<'js>

Convert from BigInt

Trait Implementations§

source§

impl<'js> AsRef<Value<'js>> for Array<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for ArrayBuffer<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for BigInt<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for Constructor<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for Exception<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for Function<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for Object<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for Promise<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for String<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for Symbol<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js, T> AsRef<Value<'js>> for TypedArray<'js, T>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> AsRef<Value<'js>> for Value<'js>

source§

fn as_ref(&self) -> &Value<'js>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'js> Clone for Value<'js>

source§

fn clone(&self) -> Value<'js>

Returns a copy 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<'js> Debug for Value<'js>

source§

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

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

impl<'js> Drop for Value<'js>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'js> From<Array<'js>> for Value<'js>

source§

fn from(value: Array<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<BigInt<'js>> for Value<'js>

source§

fn from(value: BigInt<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<Constructor<'js>> for Value<'js>

source§

fn from(value: Constructor<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<Exception<'js>> for Value<'js>

source§

fn from(value: Exception<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<Function<'js>> for Value<'js>

source§

fn from(value: Function<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<Object<'js>> for Value<'js>

source§

fn from(value: Object<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<Promise<'js>> for Value<'js>

source§

fn from(value: Promise<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<String<'js>> for Value<'js>

source§

fn from(value: String<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> From<Symbol<'js>> for Value<'js>

source§

fn from(value: Symbol<'js>) -> Value<'js>

Converts to this type from the input type.
source§

impl<'js> FromAtom<'js> for Value<'js>

source§

fn from_atom(atom: Atom<'js>) -> Result<Value<'js>, Error>

source§

impl<'js> FromJs<'js> for Value<'js>

source§

fn from_js(_: &Ctx<'js>, value: Value<'js>) -> Result<Value<'js>, Error>

source§

impl<'js> Hash for Value<'js>

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'js> IntoAtom<'js> for Value<'js>

source§

fn into_atom(self, ctx: &Ctx<'js>) -> Result<Atom<'js>, Error>

source§

impl<'js> IntoJs<'js> for &Value<'js>

source§

fn into_js(self, _: &Ctx<'js>) -> Result<Value<'js>, Error>

source§

impl<'js> IntoJs<'js> for Value<'js>

source§

fn into_js(self, _: &Ctx<'js>) -> Result<Value<'js>, Error>

source§

impl<'js> Outlive<'js> for Value<'js>

§

type Target<'to> = Value<'to>

The target which has the same type as a Self but with another lifetime 't
source§

impl<'js> PartialEq for Value<'js>

source§

fn eq(&self, other: &Value<'js>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'js> Trace<'js> for Value<'js>

source§

fn trace<'a>(&self, tracer: Tracer<'a, 'js>)

source§

impl<'js> Eq for Value<'js>

Auto Trait Implementations§

§

impl<'js> Freeze for Value<'js>

§

impl<'js> RefUnwindSafe for Value<'js>

§

impl<'js> !Send for Value<'js>

§

impl<'js> !Sync for Value<'js>

§

impl<'js> Unpin for Value<'js>

§

impl<'js> !UnwindSafe for Value<'js>

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<'js, T> AsProperty<'js, T> for T
where T: IntoJs<'js>,

source§

fn config( self, ctx: &Ctx<'js> ) -> Result<(i32, Value<'js>, Value<'js>, Value<'js>), Error>

Property configuration 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'js, T> FromParam<'js> for T
where T: FromJs<'js>,

source§

fn param_requirement() -> ParamRequirement

The parameters requirements this value requires.
source§

fn from_param<'a>(params: &mut ParamsAccessor<'a, 'js>) -> Result<T, Error>

Convert from a parameter value.
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<'js, T> IntoArg<'js> for T
where T: IntoJs<'js>,

source§

fn num_args(&self) -> usize

The number of arguments this value produces.
source§

fn into_arg(self, args: &mut Args<'js>) -> Result<(), Error>

Convert the value into an argument.
source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.