pub struct Channel {
pub rx: UnboundedReceiver<Result<Message, Error>>,
pub tx: UnboundedSender<Result<Message, Error>>,
}Expand description
A channel endpoint representing one side of a bidirectional message channel.
Channel represents a single endpoint’s view of a bidirectional communication channel.
Each endpoint has:
rx: A receiver for incoming messages (or errors) from the counterparttx: A sender for outgoing messages (or errors) to the counterpart
§Example
// Create a pair of connected channels
let (channel_a, channel_b) = Channel::duplex();
// Each channel can be used by a different component
UntypedLink::builder()
.name("connection-a")
.serve(channel_a)
.await?;Fields§
§rx: UnboundedReceiver<Result<Message, Error>>Receives messages (or errors) from the counterpart.
tx: UnboundedSender<Result<Message, Error>>Sends messages (or errors) to the counterpart.
Implementations§
Source§impl Channel
impl Channel
Sourcepub fn duplex() -> (Self, Self)
pub fn duplex() -> (Self, Self)
Create a pair of connected channel endpoints.
Returns two Channel instances that are connected to each other:
- Messages sent via
channel_a.txare received onchannel_b.rx - Messages sent via
channel_b.txare received onchannel_a.rx
§Returns
A tuple (channel_a, channel_b) of connected channel endpoints.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Channel
impl !RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl !UnwindSafe for Channel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more