Skip to main content

MessageSender

Trait MessageSender 

Source
pub trait MessageSender: NativeObject {
    // Required method
    fn send(
        &self,
        message: JsValueStore,
        target_origin: Option<JsString>,
    ) -> Result<(), JsError>;

    // Provided method
    fn stop(&self) -> Result<(), JsError> { ... }
}
Expand description

A sender of a message. When registering the postMessage API, one must also register an implementation of this trait in the context.

This trait receives a JsValueStore value and ensures it gets delivered to the correct location, be it a Rust API, or another context altogether.

Required Methods§

Source

fn send( &self, message: JsValueStore, target_origin: Option<JsString>, ) -> Result<(), JsError>

Send a message to the necessary context.

The second argument is the targetOrigin argument passed to postMessage. No default value exists, and so it must be resolved by the application. It can be used to filter messages.

§Errors

Any errors in transit should be returned here. An error should be returned before the full transfer is done and tell the application that it should retry if possible.

If an error happens after the transfer is done but before the message is handled, this must be handled by the host application, e.g., using a messageerror event.

Provided Methods§

Source

fn stop(&self) -> Result<(), JsError>

Stop the sender from receiving messages. The default implementation does nothing, but a successful implementation should try to stop any queued jobs or anything that might block the context from terminating.

§Errors

Any errors in transit should be returned here.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§