Struct rquickjs_core::Class[][src]

pub struct Class<'js, C>(_, _);
This is supported on crate feature classes only.

The class object interface

Implementations

impl<'js, C> Class<'js, C> where
    C: ClassDef
[src]

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

Wrap constructor of class

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

Initialize static data

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

Instantiate the object of class

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

Instantiate the object of class with given prototype

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

Get reference from object

pub fn try_mut<'r>(ctx: Ctx<'js>, value: &Object<'js>) -> Result<&'r mut C>[src]

Get mutable reference from object

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

Register the class

pub unsafe fn register_raw(ctx: *mut JSContext)[src]

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.

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

Get the own prototype object of a class

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

Get class from value

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

Get reference to object

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

Convert to object

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

Convert to value

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

pub fn init_def<T>(&self) -> Result<()> where
    T: ObjectDef
[src]

Initialize an object using ObjectDef

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

Get a new value

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

check wether the object contains a certain key.

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

Set a member of an object to a certain value

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

Remove a member of an object

pub fn is_empty(&self) -> bool[src]

Check the object for empty

pub fn len(&self) -> usize[src]

Get the number of properties

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

Get own string enumerable property names of an object

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

Get own property names of an object

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

Get own string enumerable properties of an object

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

Get own properties of an object

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

Get own string enumerable property values of an object

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

Get own property values of an object

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

Get an object prototype

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

Set an object prototype

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

Reference to value

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

Check the object for instance of

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

This is supported 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();

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

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

Try get bool from value

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

Try get int from value

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

Try get float from value

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

Try get any number from value

pub fn is_bool(&self) -> bool[src]

Check if the value is a bool

pub fn is_int(&self) -> bool[src]

Check if the value is an int

pub fn is_float(&self) -> bool[src]

Check if the value is a float

pub fn is_number(&self) -> bool[src]

Check if the value is an any number

pub fn is_string(&self) -> bool[src]

Check if the value is a string

pub fn is_symbol(&self) -> bool[src]

Check if the value is a symbol

pub fn is_object(&self) -> bool[src]

Check if the value is an object

pub fn is_module(&self) -> bool[src]

Check if the value is a module

pub fn is_array(&self) -> bool[src]

Check if the value is an array

pub fn is_function(&self) -> bool[src]

Check if the value is a function

pub fn is_error(&self) -> bool[src]

Check if the value is an error

pub fn as_value(&self) -> &Self[src]

Reference as value

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

Convert from value to specified type

pub fn type_of(&self) -> Type[src]

Get the type of value

pub fn type_name(&self) -> &'static str[src]

Get the name of type

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

Interprete as

Safety

You should be sure that the value already is of required type before to do it.

pub fn as_string(&self) -> Option<&String<'js>>[src]

Try reinterprete as

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

Interprete as

Safety

You should be sure that the value already is of required type before to do it.

pub fn as_symbol(&self) -> Option<&Symbol<'js>>[src]

Try reinterprete as

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

Interprete as

Safety

You should be sure that the value already is of required type before to do it.

pub fn as_object(&self) -> Option<&Object<'js>>[src]

Try reinterprete as

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

Interprete as

Safety

You should be sure that the value already is of required type before to do it.

pub fn as_array(&self) -> Option<&Array<'js>>[src]

Try reinterprete as

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

Interprete as

Safety

You should be sure that the value already is of required type before to do it.

pub fn as_function(&self) -> Option<&Function<'js>>[src]

Try reinterprete as

pub unsafe fn ref_module(&self) -> &Module<'js, Evaluated>[src]

Interprete as

Safety

You should be sure that the value already is of required type before to do it.

pub fn as_module(&self) -> Option<&Module<'js, Evaluated>>[src]

Try reinterprete as

Trait Implementations

impl<'js, C> AsMut<C> for Class<'js, C> where
    C: ClassDef
[src]

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

impl<'js, C> AsRef<Object<'js>> for Class<'js, C>[src]

impl<'js, C> AsRef<Value<'js>> for Class<'js, C>[src]

impl<'js, C> Deref for Class<'js, C>[src]

type Target = Object<'js>

The resulting type after dereferencing.

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

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

impl<'js, 't, C> Outlive<'t> for Class<'js, C>[src]

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>[src]

impl<'js, C> !Send for Class<'js, C>[src]

impl<'js, C> !Sync for Class<'js, C>[src]

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

impl<'js, C> UnwindSafe for Class<'js, C> where
    C: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.