JsValue

Struct JsValue 

Source
pub struct JsValue(/* private fields */);
Expand description

A generic JavaScript value. This can be any ECMAScript language valid value.

This is a wrapper around the actual value, which is stored in an opaque type. This allows for internal changes to the value without affecting the public API.

let mut context = Context::default();
let value = JsValue::new(3);
assert_eq!(value.to_string(&mut context), Ok(js_string!("3")));

Implementations§

Source§

impl JsValue

Source

pub fn get_iterator_from_method( &self, method: &JsObject, context: &mut Context, ) -> JsResult<IteratorRecord>

GetIteratorFromMethod ( obj, method )

More information:

Source

pub fn get_iterator( &self, hint: IteratorHint, context: &mut Context, ) -> JsResult<IteratorRecord>

GetIterator ( obj, kind )

More information:

Source§

impl JsValue

Source

pub fn ordinary_has_instance( function: &Self, object: &Self, context: &mut Context, ) -> JsResult<bool>

Abstract operation OrdinaryHasInstance ( C, O )

More information:

Source§

impl JsValue

Source

pub fn from_json(json: &Value, context: &mut Context) -> JsResult<Self>

Converts a serde_json::Value to a JsValue.

§Example
use boa_engine::{Context, JsValue};

let data = r#"
    {
        "name": "John Doe",
        "age": 43,
        "phones": [
            "+44 1234567",
            "+44 2345678"
        ]
     }"#;

let json: serde_json::Value = serde_json::from_str(data).unwrap();

let mut context = Context::default();
let value = JsValue::from_json(&json, &mut context).unwrap();
Source

pub fn to_json(&self, context: &mut Context) -> JsResult<Option<Value>>

Converts the JsValue to a serde_json::Value.

If the JsValue is Undefined, this method will return None. Otherwise it will return the corresponding serde_json::Value.

§Example
use boa_engine::{Context, JsValue};

let data = r#"
    {
        "name": "John Doe",
        "age": 43,
        "phones": [
            "+44 1234567",
            "+44 2345678"
        ]
     }"#;

let json: serde_json::Value = serde_json::from_str(data).unwrap();

let mut context = Context::default();
let value = JsValue::from_json(&json, &mut context).unwrap();

let back_to_json = value.to_json(&mut context).unwrap();
Source§

impl JsValue

Source

pub fn try_js_into<T>(&self, context: &mut Context) -> JsResult<T>
where T: TryFromJs,

This function is the inverse of TryFromJs. It tries to convert a JsValue to a given Rust type.

Source§

impl JsValue

Source

pub fn display_obj(&self, print_internals: bool) -> String

A helper function for specifically printing object values

Source§

impl JsValue

Source

pub fn deep_strict_equals( &self, other: &Self, context: &mut Context, ) -> JsResult<bool>

Deep strict equality.

If the value is an object/array, also compare the key-values. It uses strict_equals() for non-object values.

Source

pub fn strict_equals(&self, other: &Self) -> bool

Strict equality comparison.

This method is executed when doing strict equality comparisons with the === operator. For more information, check https://tc39.es/ecma262/#sec-strict-equality-comparison.

Source

pub fn equals(&self, other: &Self, context: &mut Context) -> JsResult<bool>

Abstract equality comparison.

This method is executed when doing abstract equality comparisons with the == operator. For more information, check https://tc39.es/ecma262/#sec-abstract-equality-comparison

Source

pub fn same_value(x: &Self, y: &Self) -> bool

The internal comparison abstract operation SameValue(x, y), where x and y are ECMAScript language values, produces true or false.

More information:

Source

pub fn same_value_zero(x: &Self, y: &Self) -> bool

The internal comparison abstract operation SameValueZero(x, y), where x and y are ECMAScript language values, produces true or false.

SameValueZero differs from SameValue only in its treatment of +0 and -0.

More information:

Source§

impl JsValue

Source

pub fn add(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary + operator on the value and return the result.

Source

pub fn sub(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary - operator on the value and return the result.

Source

pub fn mul(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary * operator on the value and return the result.

Source

pub fn div(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary / operator on the value and return the result.

Source

pub fn rem(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary % operator on the value and return the result.

Source

pub fn pow(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary ** operator on the value and return the result.

Source

pub fn bitand(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary & operator on the value and return the result.

Source

pub fn bitor(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary | operator on the value and return the result.

Source

pub fn bitxor(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary ^ operator on the value and return the result.

Source

pub fn shl(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary << operator on the value and return the result.

Source

pub fn shr(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary >> operator on the value and return the result.

Source

pub fn ushr(&self, other: &Self, context: &mut Context) -> JsResult<Self>

Perform the binary >>> operator on the value and return the result.

Source

pub fn instance_of( &self, target: &Self, context: &mut Context, ) -> JsResult<bool>

Abstract operation InstanceofOperator ( V, target )

More information:

Source

pub fn neg(&self, context: &mut Context) -> JsResult<Self>

Returns the negated value.

Source

pub fn not(&self) -> JsResult<bool>

Returns the negated boolean value.

Source

pub fn abstract_relation( &self, other: &Self, left_first: bool, context: &mut Context, ) -> JsResult<AbstractRelation>

Abstract relational comparison

The comparison x < y, where x and y are values, produces true, false, or undefined (which indicates that at least one operand is NaN).

In addition to x and y the algorithm takes a Boolean flag named LeftFirst as a parameter. The flag is used to control the order in which operations with potentially visible side-effects are performed upon x and y. It is necessary because ECMAScript specifies left to right evaluation of expressions. The default value of LeftFirst is true and indicates that the x parameter corresponds to an expression that occurs to the left of the y parameter’s corresponding expression.

If LeftFirst is false, the reverse is the case and operations must be performed upon y before x.

More Information:

Source

pub fn lt(&self, other: &Self, context: &mut Context) -> JsResult<bool>

The less than operator (<) returns true if the left operand is less than the right operand, and false otherwise.

More Information:

Source

pub fn le(&self, other: &Self, context: &mut Context) -> JsResult<bool>

The less than or equal operator (<=) returns true if the left operand is less than or equal to the right operand, and false otherwise.

More Information:

Source

pub fn gt(&self, other: &Self, context: &mut Context) -> JsResult<bool>

The greater than operator (>) returns true if the left operand is greater than the right operand, and false otherwise.

More Information:

Source

pub fn ge(&self, other: &Self, context: &mut Context) -> JsResult<bool>

The greater than or equal operator (>=) returns true if the left operand is greater than or equal to the right operand, and false otherwise.

More Information:

Source§

impl JsValue

Source

pub fn get_type(&self) -> Type

Get the type of a value

This is the abstract operation Type(v), as described in https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-ecmascript-language-types.

Check JsValue::type_of if you need to call the typeof operator.

Source§

impl JsValue

Source

pub fn new<T>(value: T) -> Self
where T: Into<Self>,

Create a new JsValue.

Source

pub fn variant(&self) -> JsVariant

Return the variant of this value.

Source

pub const fn undefined() -> Self

Creates a new undefined value.

Source

pub const fn null() -> Self

Creates a new null value.

Source

pub const fn nan() -> Self

Creates a new number with NaN value.

Source

pub const fn positive_infinity() -> Self

Creates a new number with Infinity value.

Source

pub const fn negative_infinity() -> Self

Creates a new number with -Infinity value.

Source

pub fn rational(rational: f64) -> Self

Creates a new number from a float.

Source

pub fn is_object(&self) -> bool

Returns true if the value is an object.

Source

pub fn as_object(&self) -> Option<JsObject>

Returns the object if the value is object, otherwise None.

Source

pub fn into_object(self) -> Option<JsObject>

Consumes the value and return the inner object if it was an object.

Source

pub fn is_callable(&self) -> bool

It determines if the value is a callable function with a [[Call]] internal method.

More information:

Source

pub fn as_callable(&self) -> Option<JsObject>

Returns the callable value if the value is callable, otherwise None.

Source

pub fn as_function(&self) -> Option<JsFunction>

Returns a JsFunction if the value is callable, otherwise None. This is equivalent to JsFunction::from_object(value.as_callable()?).

Source

pub fn is_constructor(&self) -> bool

Returns true if the value is a constructor object.

Source

pub fn as_constructor(&self) -> Option<JsObject>

Returns the constructor if the value is a constructor, otherwise None.

Source

pub fn is_promise(&self) -> bool

Returns true if the value is a promise object.

Source

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

Returns the value as a promise if the value is a promise, otherwise None.

Source

pub fn is_regexp(&self) -> bool

Returns true if the value is a regular expression object.

Source

pub fn as_regexp(&self) -> Option<JsRegExp>

Returns the value as a regular expression if the value is a regexp, otherwise None.

Source

pub fn is_symbol(&self) -> bool

Returns true if the value is a symbol.

Source

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

Returns the symbol if the value is a symbol, otherwise None.

Source

pub fn is_undefined(&self) -> bool

Returns true if the value is undefined.

Source

pub fn is_null(&self) -> bool

Returns true if the value is null.

Source

pub fn is_null_or_undefined(&self) -> bool

Returns true if the value is null or undefined.

Source

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

Returns the number if the value is a finite integral Number value, otherwise None.

More information:

Source

pub fn is_number(&self) -> bool

Returns true if the value is a number.

Source

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

Returns the number if the value is a number, otherwise None.

Source

pub fn is_string(&self) -> bool

Returns true if the value is a string.

Source

pub fn as_string(&self) -> Option<JsString>

Returns the string if the value is a string, otherwise None.

Source

pub fn is_boolean(&self) -> bool

Returns true if the value is a boolean.

Source

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

Returns the boolean if the value is a boolean, otherwise None.

Source

pub fn is_bigint(&self) -> bool

Returns true if the value is a bigint.

Source

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

Returns a BigInt if the value is a BigInt primitive.

Source

pub fn to_boolean(&self) -> bool

Converts the value to a bool type.

More information:

Source

pub fn to_primitive( &self, context: &mut Context, preferred_type: PreferredType, ) -> JsResult<Self>

The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType.

https://tc39.es/ecma262/#sec-toprimitive

Source

pub fn to_bigint(&self, context: &mut Context) -> JsResult<JsBigInt>

7.1.13 ToBigInt ( argument )

More information:

Source

pub const fn display(&self) -> ValueDisplay<'_>

Returns an object that implements Display.

By default, the internals are not shown, but they can be toggled with ValueDisplay::internals method.

§Examples
use boa_engine::JsValue;

let value = JsValue::new(3);

println!("{}", value.display());
Source

pub fn to_string(&self, context: &mut Context) -> JsResult<JsString>

Converts the value to a string.

This function is equivalent to String(value) in JavaScript.

Source

pub fn to_object(&self, context: &mut Context) -> JsResult<JsObject>

Converts the value to an Object.

This function is equivalent to Object(value) in JavaScript.

See: https://tc39.es/ecma262/#sec-toobject

Source

pub fn to_property_key(&self, context: &mut Context) -> JsResult<PropertyKey>

Converts the value to a PropertyKey, that can be used as a key for properties.

See https://tc39.es/ecma262/#sec-topropertykey

Source

pub fn to_numeric(&self, context: &mut Context) -> JsResult<Numeric>

It returns value converted to a numeric value of type Number or BigInt.

See: https://tc39.es/ecma262/#sec-tonumeric

Source

pub fn to_u32(&self, context: &mut Context) -> JsResult<u32>

Converts a value to an integral 32-bit unsigned integer.

This function is equivalent to value | 0 in JavaScript

See: https://tc39.es/ecma262/#sec-touint32

Source

pub fn to_i32(&self, context: &mut Context) -> JsResult<i32>

Converts a value to an integral 32-bit signed integer.

See: https://tc39.es/ecma262/#sec-toint32

Source

pub fn to_int8(&self, context: &mut Context) -> JsResult<i8>

7.1.10 ToInt8 ( argument )

More information:

Source

pub fn to_uint8(&self, context: &mut Context) -> JsResult<u8>

7.1.11 ToUint8 ( argument )

More information:

Source

pub fn to_uint8_clamp(&self, context: &mut Context) -> JsResult<u8>

7.1.12 ToUint8Clamp ( argument )

More information:

Source

pub fn to_int16(&self, context: &mut Context) -> JsResult<i16>

7.1.8 ToInt16 ( argument )

More information:

Source

pub fn to_uint16(&self, context: &mut Context) -> JsResult<u16>

7.1.9 ToUint16 ( argument )

More information:

Source

pub fn to_big_int64(&self, context: &mut Context) -> JsResult<i64>

7.1.15 ToBigInt64 ( argument )

More information:

Source

pub fn to_big_uint64(&self, context: &mut Context) -> JsResult<u64>

7.1.16 ToBigUint64 ( argument )

More information:

Source

pub fn to_index(&self, context: &mut Context) -> JsResult<u64>

Converts a value to a non-negative integer if it is a valid integer index value.

See: https://tc39.es/ecma262/#sec-toindex

Source

pub fn to_length(&self, context: &mut Context) -> JsResult<u64>

Converts argument to an integer suitable for use as the length of an array-like object.

See: https://tc39.es/ecma262/#sec-tolength

Source

pub fn to_integer_or_infinity( &self, context: &mut Context, ) -> JsResult<IntegerOrInfinity>

Abstract operation ToIntegerOrInfinity ( argument )

This method converts a Value to an integer representing its Number value with fractional part truncated, or to +∞ or -∞ when that Number value is infinite.

More information:

Source

pub fn to_number(&self, context: &mut Context) -> JsResult<f64>

Converts a value to a double precision floating point.

This function is equivalent to the unary + operator (+value) in JavaScript

See: https://tc39.es/ecma262/#sec-tonumber

Source

pub fn to_f16(&self, context: &mut Context) -> JsResult<f16>

Converts a value to a 16-bit floating point.

Source

pub fn to_f32(&self, context: &mut Context) -> JsResult<f32>

Converts a value to a 32 bit floating point.

Source

pub fn to_numeric_number(&self, context: &mut Context) -> JsResult<f64>

This is a more specialized version of to_numeric, including BigInt.

This function is equivalent to Number(value) in JavaScript

See: https://tc39.es/ecma262/#sec-tonumeric

Source

pub fn require_object_coercible(&self) -> JsResult<&Self>

Check if the Value can be converted to an Object

The abstract operation RequireObjectCoercible takes argument argument. It throws an error if argument is a value that cannot be converted to an Object using ToObject. It is defined by Table 15

More information:

Source

pub fn to_property_descriptor( &self, context: &mut Context, ) -> JsResult<PropertyDescriptor>

The abstract operation ToPropertyDescriptor.

More information:

Source

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

typeof operator. Returns a string representing the type of the given ECMA Value.

More information:

Source

pub fn js_type_of(&self) -> JsString

Same as JsValue::type_of, but returning a JsString instead.

Source

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

Maps a JsValue into Option<T> where T is the result of an operation on a defined value. If the value is JsValue::undefined, then JsValue::map will return None.

§Example
use boa_engine::{Context, JsValue};

let mut context = Context::default();

let defined_value = JsValue::from(5);
let undefined = JsValue::undefined();

let defined_result = defined_value
    .map(|v| v.add(&JsValue::from(5), &mut context))
    .transpose()
    .unwrap();
let undefined_result = undefined
    .map(|v| v.add(&JsValue::from(5), &mut context))
    .transpose()
    .unwrap();

assert_eq!(defined_result, Some(JsValue::from(10u8)));
assert_eq!(undefined_result, None);
Source

pub fn map_or<T, F>(&self, default: T, f: F) -> T
where F: FnOnce(&JsValue) -> T,

Maps a JsValue into T where T is the result of an operation on a defined value. If the value is JsValue::undefined, then JsValue::map will return the provided default value.

§Example
use boa_engine::{Context, JsValue};

let mut context = Context::default();

let defined_value = JsValue::from(5);
let undefined = JsValue::undefined();

let defined_result = defined_value
    .map_or(Ok(JsValue::new(true)), |v| {
        v.add(&JsValue::from(5), &mut context)
    })
    .unwrap();
let undefined_result = undefined
    .map_or(Ok(JsValue::new(true)), |v| {
        v.add(&JsValue::from(5), &mut context)
    })
    .unwrap();

assert_eq!(defined_result, JsValue::new(10));
assert_eq!(undefined_result, JsValue::new(true));

Trait Implementations§

Source§

impl Clone for JsValue

Source§

fn clone(&self) -> JsValue

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 Debug for JsValue

Source§

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

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

impl Default for JsValue

Source§

fn default() -> Self

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

impl Drop for JsValue

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Finalize for JsValue

Source§

fn finalize(&self)

Cleanup logic for a type.
Source§

impl From<&PropertyKey> for JsValue

Source§

fn from(property_key: &PropertyKey) -> Self

Converts to this type from the input type.
Source§

impl From<()> for JsValue

Source§

fn from((): ()) -> Self

Converts to this type from the input type.
Source§

impl From<GeneratorResumeKind> for JsValue

Source§

fn from(value: GeneratorResumeKind) -> Self

Converts to this type from the input type.
Source§

impl From<JsArray> for JsValue

Source§

fn from(o: JsArray) -> Self

Converts to this type from the input type.
Source§

impl From<JsArrayBuffer> for JsValue

Source§

fn from(o: JsArrayBuffer) -> Self

Converts to this type from the input type.
Source§

impl From<JsBigInt> for JsValue

Source§

fn from(value: JsBigInt) -> Self

Converts to this type from the input type.
Source§

impl From<JsBigInt64Array> for JsValue

Source§

fn from(o: JsBigInt64Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsBigUint64Array> for JsValue

Source§

fn from(o: JsBigUint64Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsDataView> for JsValue

Source§

fn from(o: JsDataView) -> Self

Converts to this type from the input type.
Source§

impl From<JsDate> for JsValue

Source§

fn from(o: JsDate) -> Self

Converts to this type from the input type.
Source§

impl From<JsFloat16Array> for JsValue

Source§

fn from(o: JsFloat16Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsFloat32Array> for JsValue

Source§

fn from(o: JsFloat32Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsFloat64Array> for JsValue

Source§

fn from(o: JsFloat64Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsFunction> for JsValue

Source§

fn from(o: JsFunction) -> Self

Converts to this type from the input type.
Source§

impl From<JsGenerator> for JsValue

Source§

fn from(o: JsGenerator) -> Self

Converts to this type from the input type.
Source§

impl From<JsInt16Array> for JsValue

Source§

fn from(o: JsInt16Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsInt32Array> for JsValue

Source§

fn from(o: JsInt32Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsInt8Array> for JsValue

Source§

fn from(o: JsInt8Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsMap> for JsValue

Source§

fn from(o: JsMap) -> Self

Converts to this type from the input type.
Source§

impl From<JsMapIterator> for JsValue

Source§

fn from(o: JsMapIterator) -> Self

Converts to this type from the input type.
Source§

impl From<JsObject> for JsValue

Source§

fn from(object: JsObject) -> Self

Converts to this type from the input type.
Source§

impl From<JsPromise> for JsValue

Source§

fn from(o: JsPromise) -> Self

Converts to this type from the input type.
Source§

impl From<JsProxy> for JsValue

Source§

fn from(o: JsProxy) -> Self

Converts to this type from the input type.
Source§

impl From<JsRegExp> for JsValue

Source§

fn from(o: JsRegExp) -> Self

Converts to this type from the input type.
Source§

impl From<JsSet> for JsValue

Source§

fn from(o: JsSet) -> Self

Converts to this type from the input type.
Source§

impl From<JsSetIterator> for JsValue

Source§

fn from(o: JsSetIterator) -> Self

Converts to this type from the input type.
Source§

impl From<JsSharedArrayBuffer> for JsValue

Source§

fn from(o: JsSharedArrayBuffer) -> Self

Converts to this type from the input type.
Source§

impl From<JsStr<'_>> for JsValue

Source§

fn from(value: JsStr<'_>) -> Self

Converts to this type from the input type.
Source§

impl From<JsString> for JsValue

Source§

fn from(value: JsString) -> Self

Converts to this type from the input type.
Source§

impl From<JsSymbol> for JsValue

Source§

fn from(value: JsSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<JsTypedArray> for JsValue

Source§

fn from(o: JsTypedArray) -> Self

Converts to this type from the input type.
Source§

impl From<JsUint16Array> for JsValue

Source§

fn from(o: JsUint16Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsUint32Array> for JsValue

Source§

fn from(o: JsUint32Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsUint8Array> for JsValue

Source§

fn from(o: JsUint8Array) -> Self

Converts to this type from the input type.
Source§

impl From<JsUint8ClampedArray> for JsValue

Source§

fn from(o: JsUint8ClampedArray) -> Self

Converts to this type from the input type.
Source§

impl From<JsVariant> for JsValue

Source§

fn from(value: JsVariant) -> Self

Converts to this type from the input type.
Source§

impl From<Numeric> for JsValue

Source§

fn from(value: Numeric) -> Self

Converts to this type from the input type.
Source§

impl From<PropertyKey> for JsValue

Source§

fn from(property_key: PropertyKey) -> Self

Converts to this type from the input type.
Source§

impl<A: TryIntoJsArguments, R: TryFromJs> From<TypedJsFunction<A, R>> for JsValue

Source§

fn from(o: TypedJsFunction<A, R>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for JsValue

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for JsValue

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for JsValue

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for JsValue

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for JsValue

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for JsValue

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for JsValue

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for JsValue

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for JsValue

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for JsValue

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for JsValue

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for JsValue

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for JsValue

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for JsValue

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl Hash for JsValue

Source§

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

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 PartialEq for JsValue

Source§

fn eq(&self, other: &Self) -> 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 Trace for JsValue

Source§

unsafe fn trace(&self, tracer: &mut Tracer)

Marks all contained Gcs. Read more
Source§

unsafe fn trace_non_roots(&self)

Trace handles located in GC heap, and mark them as non root. Read more
Source§

fn run_finalizer(&self)

Runs Finalize::finalize on this object and all contained subobjects.
Source§

impl TryFromJs for JsValue

Source§

fn try_from_js(value: &JsValue, _context: &mut Context) -> JsResult<Self>

This function tries to convert a JavaScript value into Self.
Source§

impl TryIntoJs for JsValue

Source§

fn try_into_js(&self, _context: &mut Context) -> JsResult<JsValue>

This function tries to convert a Self into JsValue.
Source§

impl Eq for JsValue

Auto Trait Implementations§

§

impl Freeze for JsValue

§

impl !RefUnwindSafe for JsValue

§

impl !Send for JsValue

§

impl !Sync for JsValue

§

impl Unpin for JsValue

§

impl !UnwindSafe for JsValue

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

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. 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<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<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> 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> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
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> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. 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<'a, T> TryFromJsArgument<'a> for T
where T: TryFromJs,

Source§

fn try_from_js_argument( _: &'a JsValue, rest: &'a [JsValue], context: &mut Context, ) -> Result<(T, &'a [JsValue]), JsError>

Try to convert a JS argument into a Rust value, returning the value and the rest of the arguments to be parsed. Read more
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> TryIntoJsResult for T
where T: TryIntoJs,

Source§

fn try_into_js_result(self, ctx: &mut Context) -> Result<JsValue, JsError>

Try to convert a Rust value into a JsResult<JsValue>. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,