Skip to content

Channels Overview

This page covers Rust-specific channel details. For the general concept of what a channel is, see Channels.

All channels implement the CommandChannel trait:

pub trait CommandChannel: Send + Sync {
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>>;
}
MethodDescription
id()Unique identifier for this channel
start()Handshake/setup, called once before first recv
close()Tear down; subsequent send returns Err(Closed), recv returns None
send(msg)Fire-and-forget send to the peer
recv()Await the next inbound message, or None on close

The async methods return BoxFuture so dyn CommandChannel stays object-safe (same shape #[async_trait] would produce).

use std::sync::Arc;
use coralstack_cmd_ipc::prelude::*;
let channel: Arc<dyn CommandChannel> = /* ... */;
let driver = registry.register_channel(channel).await?;
tokio::spawn(driver); // or any executor

register_channel returns a Future<Output = ()> — spawn it yourself on tokio, async-std, smol, or futures::executor::ThreadPool. The future resolves when the channel closes, and commands owned by the channel are cleaned up automatically at that point.