Trait rquickjs::class::JsClass

source ·
pub trait JsClass<'js>: Trace<'js> {
    type Mutable: Mutability;

    const NAME: &'static str;

    // Required methods
    fn class_id() -> &'static ClassId;
    fn prototype(ctx: &Ctx<'js>) -> Result<Option<Object<'js>>, Error>;
    fn constructor(ctx: &Ctx<'js>) -> Result<Option<Constructor<'js>>, Error>;

    // Provided method
    fn function() -> Option<StaticJsFn> { ... }
}
Expand description

The trait which allows Rust types to be used from JavaScript.

Required Associated Types§

source

type Mutable: Mutability

Can the type be mutated while a JavaScript value.

This should either be Readable or Writable.

Required Associated Constants§

source

const NAME: &'static str

The name the constructor has in JavaScript

Required Methods§

source

fn class_id() -> &'static ClassId

A unique id for the class.

source

fn prototype(ctx: &Ctx<'js>) -> Result<Option<Object<'js>>, Error>

Returns the class prototype,

source

fn constructor(ctx: &Ctx<'js>) -> Result<Option<Constructor<'js>>, Error>

Returns a predefined constructor for this specific class type if there is one.

Provided Methods§

source

fn function() -> Option<StaticJsFn>

A possible call function.

Returning a function from this method makes any objects with this class callable as if it is a function object..

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'js> JsClass<'js> for RustFunction<'js>

source§

const NAME: &'static str = "RustFunction"

§

type Mutable = Readable