Struct quickjs_rusty::value::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.

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_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_function(&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_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 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 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 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§

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

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 ToOwnedJsValue for OwnedJsValue

for some cases like HashMap<String, OwnedJsValue>

source§

impl TryFrom<OwnedJsValue> for BigInt

§

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

§

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>

§

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>

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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>

§

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 bool

§

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

§

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

§

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

§

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

§

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

§

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

§

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 Send for OwnedJsValue

source§

impl Sync for OwnedJsValue

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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.