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§
Sourcetype CallbackId: Clone
type CallbackId: Clone
An identifier for a callback retained by this guest.
Required Methods§
Sourcefn scope(&self) -> RealmScope<Self::RealmId>
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.
Sourcefn retain_callback(
&mut self,
callback: &Self::Value,
) -> Result<RetainedCallback<Self::RealmId, Self::CallbackId>, Self::Error>
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.
Sourcefn release_callback(
&mut self,
callback: &RetainedCallback<Self::RealmId, Self::CallbackId>,
) -> Result<(), Self::Error>
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.
Sourcefn register_intrinsic(
&mut self,
name: &'static str,
arity: u8,
callback: NativeIntrinsic<Self>,
) -> Result<(), Self::Error>where
Self: Sized,
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.
Sourcefn invoke_retained_callback(
&mut self,
callback: &RetainedCallback<Self::RealmId, Self::CallbackId>,
arguments: &[Self::Value],
) -> Result<Self::Value, Self::Error>
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".