Trait JsClass

Source
pub trait JsClass<'js>:
    Trace<'js>
    + JsLifetime<'js>
    + Sized {
    type Mutable: Mutability;

    const NAME: &'static str;
    const CALLABLE: bool = false;

    // Required method
    fn constructor(ctx: &Ctx<'js>) -> Result<Option<Constructor<'js>>>;

    // Provided methods
    fn prototype(ctx: &Ctx<'js>) -> Result<Option<Object<'js>>> { ... }
    fn call<'a>(
        this: &JsCell<'js, Self>,
        params: Params<'a, 'js>,
    ) -> Result<Value<'js>> { ... }
}
Expand description

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

Required Associated Constants§

Source

const NAME: &'static str

The name the constructor has in JavaScript

Provided Associated Constants§

Source

const CALLABLE: bool = false

Is this class a function.

Required Associated Types§

Source

type Mutable: Mutability

Can the type be mutated while a JavaScript value.

This should either be Readable or Writable.

Required Methods§

Source

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

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

Provided Methods§

Source

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

Returns the class prototype,

Source

fn call<'a>( this: &JsCell<'js, Self>, params: Params<'a, 'js>, ) -> Result<Value<'js>>

The function which will be called if Self::CALLABLE is true and an an object with this class is called as if it is a function.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Source§

const NAME: &'static str = "RustFunction"

Source§

const CALLABLE: bool = true

Source§

type Mutable = Readable