Struct rquickjs_core::class::Class

source ·
pub struct Class<'js, C>(_, _);
Available on crate feature classes only.
Expand description

The class object interface

Implementations§

source§

impl<'js, C> Class<'js, C>where C: ClassDef,

source

pub fn constructor<F>(func: F) -> Constructor<C, F>

Wrap constructor of class

source

pub fn static_init(ctx: Ctx<'js>, func: &Function<'js>) -> Result<()>

Initialize static data

source

pub fn instance(ctx: Ctx<'js>, value: C) -> Result<Class<'js, C>>

Instantiate the object of class

source

pub fn instance_proto( ctx: Ctx<'js>, value: C, proto: Object<'js> ) -> Result<Class<'js, C>>

Instantiate the object of class with given prototype

source

pub fn try_ref<'r>(ctx: Ctx<'js>, value: &Object<'js>) -> Result<&'r C>

Get reference from object

source

pub fn register(ctx: Ctx<'js>) -> Result<()>

Register the class

source

pub unsafe fn register_raw(ctx: *mut JSContext)

Register the class using raw context

Safety

This function must only be called from js_module_init function or should be called right after context initialization. From Rust code you should use Class::register instead.

source

pub fn prototype(ctx: Ctx<'js>) -> Result<Object<'js>>

Get the own prototype object of a class

source

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

Get class from value

source

pub fn as_class_def(&self) -> &C

Get reference to class definition

source

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

Get reference to object

source

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

Convert to object

source

pub fn into_value(self) -> Value<'js>

Convert to value

Methods from Deref<Target = Object<'js>>§

source

pub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<()>where K: IntoAtom<'js>, V: AsProperty<'js, P>,

Available on crate feature properties only.

Define a property of an object

// Define readonly property without value
obj.prop("no_val", ()).unwrap();
// Define readonly property with value
obj.prop("ro_str", "Some const text").unwrap();
// Define readonly property with value and make it to be writable
obj.prop("ro_str2", Property::from("Some const text").writable()).unwrap();
// Define readonly property using getter and make it to be enumerable
obj.prop("ro_str_get", Accessor::from(|| "Some readable text").enumerable()).unwrap();
// Define readonly property using getter and setter
obj.prop("ro_str_get_set",
    Accessor::from(|| "Some text")
        .set(|new_val: String| { /* do something */ })
).unwrap();
source

pub fn init_def<T>(&self) -> Result<()>where T: ObjectDef,

Initialize an object using ObjectDef

source

pub fn get<K: IntoAtom<'js>, V: FromJs<'js>>(&self, k: K) -> Result<V>

Get a new value

source

pub fn contains_key<K>(&self, k: K) -> Result<bool>where K: IntoAtom<'js>,

check wether the object contains a certain key.

source

pub fn set<K: IntoAtom<'js>, V: IntoJs<'js>>( &self, key: K, value: V ) -> Result<()>

Set a member of an object to a certain value

source

pub fn remove<K: IntoAtom<'js>>(&self, key: K) -> Result<()>

Remove a member of an object

source

pub fn is_empty(&self) -> bool

Check the object for empty

source

pub fn len(&self) -> usize

Get the number of properties

source

pub fn keys<K: FromAtom<'js>>(&self) -> ObjectKeysIter<'js, K>

Get own string enumerable property names of an object

source

pub fn own_keys<K: FromAtom<'js>>( &self, filter: Filter ) -> ObjectKeysIter<'js, K>

Get own property names of an object

source

pub fn props<K: FromAtom<'js>, V: FromJs<'js>>(&self) -> ObjectIter<'js, K, V>

Get own string enumerable properties of an object

source

pub fn own_props<K: FromAtom<'js>, V: FromJs<'js>>( &self, filter: Filter ) -> ObjectIter<'js, K, V>

Get own properties of an object

source

pub fn values<K: FromAtom<'js>>(&self) -> ObjectValuesIter<'js, K>

Get own string enumerable property values of an object

source

pub fn own_values<K: FromAtom<'js>>( &self, filter: Filter ) -> ObjectValuesIter<'js, K>

Get own property values of an object

source

pub fn get_prototype(&self) -> Result<Object<'js>>

Get an object prototype

source

pub fn set_prototype(&self, proto: &Object<'js>) -> Result<()>

Set an object prototype

source

pub fn is_instance_of(&self, class: impl AsRef<Value<'js>>) -> bool

Check instance of object

source

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

Reference to value

source

pub fn instance_of<C: ClassDef>(&self) -> bool

Check the object for instance of

Methods from Deref<Target = Value<'js>>§

source

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

Try get bool from value

source

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

Try get int from value

source

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

Try get float from value

source

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

Try get any number from value

source

pub fn is_null(&self) -> bool

source

pub fn is_undefined(&self) -> bool

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_error(&self) -> bool

Check if the value is an error

source

pub fn as_value(&self) -> &Self

Reference as value

source

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

Convert from value to specified type

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

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

Interprete as

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 reinterprete as

source

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

Interprete as

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 reinterprete as

source

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

Interprete as

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 reinterprete as

source

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

Interprete as

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 reinterprete as

source

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

Interprete as

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 reinterprete as

source

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

Interprete as

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 reinterprete as

Trait Implementations§

source§

impl<'js, C> AsRef<C> for Class<'js, C>where C: ClassDef,

source§

fn as_ref(&self) -> &C

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

impl<'js, C> AsRef<Object<'js>> for Class<'js, C>

source§

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

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

impl<'js, C> AsRef<Value<'js>> for Class<'js, C>

source§

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

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

impl<'js, C> Deref for Class<'js, C>

§

type Target = Object<'js>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'js, C> FromJs<'js> for Class<'js, C>where C: ClassDef,

source§

fn from_js(ctx: Ctx<'js>, value: Value<'js>) -> Result<Self>

source§

impl<'js, C> IntoJs<'js> for Class<'js, C>where C: ClassDef,

source§

fn into_js(self, ctx: Ctx<'js>) -> Result<Value<'js>>

source§

impl<'js, 't, C> Outlive<'t> for Class<'js, C>

§

type Target = Class<'t, C>

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

Auto Trait Implementations§

§

impl<'js, C> RefUnwindSafe for Class<'js, C>where C: RefUnwindSafe,

§

impl<'js, C> !Send for Class<'js, C>

§

impl<'js, C> !Sync for Class<'js, C>

§

impl<'js, C> Unpin for Class<'js, C>where C: Unpin,

§

impl<'js, C> !UnwindSafe for Class<'js, C>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<'js, T> AsProperty<'js, T> for Twhere T: IntoJs<'js>,

source§

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

Available on crate feature properties only.
Property configuration Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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> IntoInput<'js> for Twhere T: IntoJs<'js>,

source§

fn num_args(&self) -> usize

Get actual number of arguments
source§

fn into_input(self, input: &mut CallInput<'js>) -> Result<(), Error>

Put the value into inputs
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
source§

impl<T> ParallelSend for T