Skip to main content

Class

Struct Class 

Source
pub struct Class<V: JSValueImpl>(/* private fields */);
Expand description

Represents a JavaScript class constructor

This struct encapsulates a JavaScript object that serves as a class constructor. It is used to create class instances and manage class lifecycle.

Implementations§

Source§

impl<V> Class<V>

Source

pub fn instance<JC: JSClass<V>>(self, value: JC) -> JSObject<V>

Create a new instance of the class

Source

pub fn instance_of<JC: JSClass<V>>(object: &JSObject<V>) -> bool

Check if the object is an instance of the specified class

Source

pub fn lookup<JC: JSClass<V>>(context: &JSContext<V::Context>) -> JSResult<Self>

Returns the registered constructor for a class type.

Source

pub fn prototype<JC: JSClass<V>>( context: &JSContext<V::Context>, ) -> JSResult<JSObject<V>>

Source

pub fn from_object<JC: JSClass<V>>(obj: &JSObject<V>) -> Option<Self>

Construct a Class constructor from a JSObject if it is an instance of the specified class

§Arguments
  • obj - The JSObject to check and convert
§Returns
  • Some(Class) if the object is an instance of the specified class
  • None if the object is not an instance of the specified class

Methods from Deref<Target = JSObject<V>>§

Source

pub fn borrow<T>(&self) -> JSResult<Ref<'_, T>>
where T: JSClass<V>,

Borrow the underlying data from an instance

Source

pub fn borrow_mut<T>(&self) -> JSResult<RefMut<'_, T>>
where T: JSClass<V>,

Mutably borrow the underlying data from an instance

Source

pub fn prototype(&self, proto: JSObject<V>) -> bool

Source

pub fn to_json_string(&self) -> JSResult<String>

Convert JSObject to JSON string using JavaScript’s JSON.stringify

Source

pub fn set<'a, K, KV>(&'a self, k: K, kv: KV) -> JSResult<&'a Self>
where K: Into<PropertyKey<'a, V>>, KV: IntoJSValue<V>,

Source

pub fn define_property<'a, K>( &'a self, k: K, descriptor: PropertyDescriptor<V>, ) -> JSResult<&'a Self>
where K: Into<PropertyKey<'a, V>>,

Source

pub fn delete<'a, K>(&'a self, k: K) -> JSResult<bool>
where K: Into<PropertyKey<'a, V>>,

Source

pub fn has_property<'a, K>(&self, k: K) -> JSResult<bool>
where K: Into<PropertyKey<'a, V>>,

Source

pub fn get<'a, K, T>(&'a self, k: K) -> JSResult<T>
where K: Into<PropertyKey<'a, V>>, T: FromJSValue<V>,

Source

pub fn get_opt<'a, K, T>(&'a self, k: K) -> JSResult<Option<T>>
where K: Into<PropertyKey<'a, V>>, T: FromJSValue<V>,

Source

pub fn as_js_value(&self) -> &JSValue<V>

Source

pub fn entries(&self) -> JSResult<Vec<Entry<V>>>

Returns an iterator over the object’s own enumerable string-keyed property [key, value] pairs.

Source

pub fn entries_as<K, V2>(&self) -> JSResult<Vec<(K, V2)>>
where K: FromJSValue<V>, V2: FromJSValue<V>,

Returns entries with converted types

Source

pub fn own_keys(&self) -> JSResult<Vec<V>>

Returns an array of a given object’s own enumerable property names

Source

pub fn values(&self) -> JSResult<impl Iterator<Item = JSValue<V>> + '_>

Returns an iterator over the object’s own enumerable string-keyed property values.

Source

pub fn values_as<T>(&self) -> JSResult<Vec<T>>
where T: FromJSValue<V>,

Returns values with converted type

Source

pub fn keys(&self) -> JSResult<impl Iterator<Item = JSValue<V>> + '_>

Returns an iterator over the object’s own enumerable string-keyed property names.

Source

pub fn keys_as<K>(&self) -> JSResult<Vec<K>>
where K: FromJSValue<V>,

Returns keys with converted type

Methods from Deref<Target = JSValue<V>>§

Source

pub fn type_of(&self) -> JSValueType

Source

pub fn is_object(&self) -> bool

Source

pub fn is_array(&self) -> bool

Source

pub fn is_array_buffer(&self) -> bool

Source

pub fn is_function(&self) -> bool

Source

pub fn is_constructor(&self) -> bool

Source

pub fn is_promise(&self) -> bool

Source

pub fn is_error(&self) -> bool

Source

pub fn is_exception(&self) -> bool

Source

pub fn is_undefined(&self) -> bool

Source

pub fn is_null(&self) -> bool

Source

pub fn is_boolean(&self) -> bool

Source

pub fn is_number(&self) -> bool

Source

pub fn is_bigint(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_symbol(&self) -> bool

Source

pub fn is_date(&self) -> bool

Source

pub fn is_proxy(&self) -> bool

Source

pub fn as_value(&self) -> &V

Source

pub fn context(&self) -> JSContext<V::Context>

Returns the context associated with this value.

Trait Implementations§

Source§

impl<V> Deref for Class<V>
where V: JSValueImpl,

Source§

type Target = JSObject<V>

The resulting type after dereferencing.
Source§

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

Dereferences the value.

Auto Trait Implementations§

§

impl<V> Freeze for Class<V>
where V: Freeze,

§

impl<V> RefUnwindSafe for Class<V>
where V: RefUnwindSafe,

§

impl<V> Send for Class<V>
where V: Send,

§

impl<V> Sync for Class<V>
where V: Sync,

§

impl<V> Unpin for Class<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for Class<V>
where V: UnsafeUnpin,

§

impl<V> UnwindSafe for Class<V>
where V: UnwindSafe,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more