Skip to main content

NativeGuest

Trait NativeGuest 

Source
pub trait NativeGuest {
    type Value;
    type RealmId: Clone + PartialEq;
    type CallbackId: Clone;
    type Error;

    // Required methods
    fn scope(&self) -> RealmScope<Self::RealmId>;
    fn retain_callback(
        &mut self,
        callback: &Self::Value,
    ) -> Result<RetainedCallback<Self::RealmId, Self::CallbackId>, Self::Error>;
    fn release_callback(
        &mut self,
        callback: &RetainedCallback<Self::RealmId, Self::CallbackId>,
    ) -> Result<(), Self::Error>;
    fn register_intrinsic(
        &mut self,
        name: &'static str,
        arity: u8,
        callback: NativeIntrinsic<Self>,
    ) -> Result<(), Self::Error>
       where Self: Sized;
    fn invoke_retained_callback(
        &mut self,
        callback: &RetainedCallback<Self::RealmId, Self::CallbackId>,
        arguments: &[Self::Value],
    ) -> Result<Self::Value, Self::Error>;
}
Expand description

A guest implementation that exposes typed values and retained callbacks.

Value, RealmId, CallbackId, and Error remain implementation-defined. In particular, this interface does not impose a shared host value enum.

Required Associated Types§

Source

type Value

The guest’s native value representation.

Source

type RealmId: Clone + PartialEq

An identifier for one realm owned by this guest.

Source

type CallbackId: Clone

An identifier for a callback retained by this guest.

Source

type Error

Errors produced while invoking a callback.

Required Methods§

Source

fn scope(&self) -> RealmScope<Self::RealmId>

Return this guest’s current realm and generation, rather than accepting a caller-supplied scope as authority to enter the guest.

Source

fn retain_callback( &mut self, callback: &Self::Value, ) -> Result<RetainedCallback<Self::RealmId, Self::CallbackId>, Self::Error>

Root an executable guest callback until release or realm teardown. Reject values that are not callable without evaluating their source.

Source

fn release_callback( &mut self, callback: &RetainedCallback<Self::RealmId, Self::CallbackId>, ) -> Result<(), Self::Error>

Revoke dispatch and release the guest root. Other token clones must become unusable. Unknown, released and stale tokens must be rejected.

Source

fn register_intrinsic( &mut self, name: &'static str, arity: u8, callback: NativeIntrinsic<Self>, ) -> Result<(), Self::Error>
where Self: Sized,

Install a compiled typed host entry point before page scripts execute. Guest-to-host conversions belong to the backend and must preserve value identity, UTF-16 code units and buffer ownership without serializing JS.

Source

fn invoke_retained_callback( &mut self, callback: &RetainedCallback<Self::RealmId, Self::CallbackId>, arguments: &[Self::Value], ) -> Result<Self::Value, Self::Error>

Invoke a retained callback with typed arguments.

Implementations must check that callback is current in self.scope() before executing it, and reject an unknown callback identifier. This method’s contract does not claim that any particular guest currently enforces those checks.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§