Skip to main content

CommandChannel

Trait CommandChannel 

Source
pub trait CommandChannel: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn start(&self) -> BoxFuture<'_, Result<(), ChannelError>>;
    fn close(&self) -> BoxFuture<'_, ()>;
    fn send(&self, msg: Message) -> Result<(), ChannelError>;
    fn recv(&self) -> BoxFuture<'_, Option<Message>>;
}
Expand description

Transport carrying Messages between two command registries.

Every method takes &self so the channel can be shared across tasks as an Arc<dyn CommandChannel>. Implementations provide their own interior synchronization. The registry drives recv from a single task, so implementations may assume a single concurrent recv caller.

The async methods return BoxFuture rather than impl Future so dyn CommandChannel is object-safe. This is the same shape #[async_trait] produces internally, written out by hand to avoid the dependency.

Required Methods§

Source

fn id(&self) -> &str

Stable identifier used by the registry to key routing tables.

Source

fn start(&self) -> BoxFuture<'_, Result<(), ChannelError>>

Performs any connection/handshake setup. Called once by the registry before the first recv.

Source

fn close(&self) -> BoxFuture<'_, ()>

Releases any resources and signals the peer that the channel is going away. After close, send must return Err(Closed) and recv must return None.

Source

fn send(&self, msg: Message) -> Result<(), ChannelError>

Fire-and-forget send. Returns immediately without waiting for the peer to receive the message.

Source

fn recv(&self) -> BoxFuture<'_, Option<Message>>

Awaits the next incoming message. Returns None when the channel has been closed by either side.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§