Skip to main content

OwnedJsValue

Struct OwnedJsValue 

Source
pub struct OwnedJsValue { /* private fields */ }
Expand description

OwnedJsValue wraps a Javascript value owned by the QuickJs runtime.

Guarantees cleanup of resources by dropping the value from the runtime.

Safety:

This type is Send and Sync only for convenience, since OwnedJsValue itself is just a wrapper around a raw pointer. But any operation on the underlying raw pointer is unsafe. Make sure using it in a same thread.

Implementations§

Source§

impl OwnedJsValue

Source

pub fn context(&self) -> *mut JSContext

Source

pub fn new(context: *mut JSContext, value: JSValue) -> Self

Create a new OwnedJsValue from a JsValue. This will NOT increase the ref count of the underlying value. So you have to manage memory yourself. Be careful when using this.

Source

pub fn own(context: *mut JSContext, value: &JSValue) -> Self

Create a new OwnedJsValue from a JsValue. This will increase the ref count of the underlying value.

Source

pub fn tag(&self) -> JsTag

Source

pub unsafe fn as_inner(&self) -> &JSValue

Get the inner JSValue without increasing ref count.

Unsafe because the caller must ensure proper memory management.

Source

pub unsafe fn extract(self) -> JSValue

Extract the underlying JSValue.

Unsafe because the caller must ensure memory management. (eg JS_FreeValue)

Source

pub fn replace(&mut self, new: JSValue)

Replace the underlying JSValue. This will decrease the ref count of the old value but remain the ref count of the new value.

Source

pub fn is_null(&self) -> bool

Check if this value is null.

Source

pub fn is_undefined(&self) -> bool

Check if this value is undefined.

Source

pub fn is_bool(&self) -> bool

Check if this value is bool.

Source

pub fn is_int(&self) -> bool

Check if this value is int.

Source

pub fn is_bigint(&self) -> bool

Check if this value is BigInt.

Source

pub fn is_short_bigint(&self) -> bool

Check if this value is BigInt, but short enough to fit in a i32

Source

pub fn is_float(&self) -> bool

Check if this value is float.

Source

pub fn is_exception(&self) -> bool

Check if this value is a Javascript exception.

Source

pub fn is_object(&self) -> bool

Check if this value is a Javascript object.

Source

pub fn is_array(&self) -> bool

Check if this value is a Javascript array.

Source

pub fn is_array_buffer(&self) -> bool

Check if this value is a Javascript array.

Source

pub fn is_proxy(&self) -> bool

Check if this value is a Javascript Proxy object.

Source

pub fn is_function(&self) -> bool

Check if this value is a Javascript function.

Source

pub fn is_constructor(&self) -> bool

Check if this value is a Javascript function.

Source

pub fn is_promise(&self) -> bool

Check if this value is a Javascript promise.

Source

pub fn is_error(&self) -> bool

Check if this value is a Javascript error.

Source

pub fn is_regexp(&self) -> bool

Check if this value is a Javascript RegExp.

Source

pub fn is_set(&self) -> bool

Check if this value is a Javascript Set.

Source

pub fn is_map(&self) -> bool

Check if this value is a Javascript Map.

Source

pub fn is_weak_set(&self) -> bool

Check if this value is a Javascript WeakSet.

Source

pub fn is_weak_map(&self) -> bool

Check if this value is a Javascript WeakMap.

Source

pub fn is_weak_ref(&self) -> bool

Check if this value is a Javascript WeakRef.

Source

pub fn is_data_view(&self) -> bool

Check if this value is a Javascript DataView.

Source

pub fn is_module(&self) -> bool

Check if this value is a Javascript module.

Source

pub fn is_string(&self) -> bool

Check if this value is a Javascript string.

Source

pub fn is_compiled_function(&self) -> bool

Check if this value is a bytecode compiled function.

Source

pub fn to_bool(&self) -> Result<bool, ValueError>

Convert this value into a bool

Source

pub fn to_int(&self) -> Result<i32, ValueError>

Convert this value into an i32

Source

pub fn to_float(&self) -> Result<f64, ValueError>

Convert this value into an f64

Source

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

Convert this value into a string

Source

pub fn to_array(&self) -> Result<OwnedJsArray, ValueError>

Source

pub fn get_proxy_target( &self, recursive: bool, ) -> Result<OwnedJsValue, ValueError>

Source

pub fn try_into_object(self) -> Result<OwnedJsObject, ValueError>

Try convert this value into a object

Source

pub fn to_date(&self) -> Result<DateTime<Utc>, ValueError>

Source

pub fn to_bigint(&self) -> Result<BigInt, ValueError>

Source

pub fn try_into_function(self) -> Result<JsFunction, ValueError>

Try convert this value into a function

Source

pub fn try_into_promise(self) -> Result<OwnedJsPromise, ValueError>

Try convert this value into a function

Source

pub fn try_into_compiled_function( self, ) -> Result<JsCompiledFunction, ValueError>

Try convert this value into a compiled function

Source

pub fn try_into_module(self) -> Result<JsModule, ValueError>

Try convert this value into a module

Source

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

Call the Javascript .toString() method on this value.

Source

pub fn to_json_string(&self, space: u8) -> Result<String, ExecutionError>

Call the Javascript JSON.stringify() method on this value.

Trait Implementations§

Source§

impl Clone for OwnedJsValue

Source§

fn clone(&self) -> Self

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 OwnedJsValue

Source§

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

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

impl Drop for OwnedJsValue

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T> From<(*mut JSContext, T)> for OwnedJsValue
where T: ToOwnedJsValue,

Source§

fn from((context, value): (*mut JSContext, T)) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for OwnedJsValue

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Send for OwnedJsValue

Source§

impl Sync for OwnedJsValue

Source§

impl ToOwnedJsValue for OwnedJsValue

for some cases like HashMap<String, OwnedJsValue>

Source§

impl TryFrom<OwnedJsValue> for bool

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for i32

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for f64

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for String

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for DateTime<Utc>

Available on crate feature chrono only.
Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for BigInt

Available on crate feature bigint only.
Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for i64

Available on crate feature bigint only.
Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for u64

Available on crate feature bigint only.
Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for i128

Available on crate feature bigint only.
Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for u128

Available on crate feature bigint only.
Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for BigInt

Available on crate feature bigint only.
Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for Option<T>

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for Vec<T>

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K: From<String> + PartialEq + Eq + Hash, V: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for HashMap<K, V>

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for JsFunction

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for OwnedJsPromise

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for OwnedJsArray

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for OwnedJsObject

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for JsCompiledFunction

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<OwnedJsValue> for JsModule

Source§

type Error = ValueError

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

fn try_from(value: OwnedJsValue) -> Result<Self, Self::Error>

Performs the conversion.

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