pub struct Party<T> { /* private fields */ }Expand description
One party of a mesh: its senders to every party and its receivers from
every party, both indexed by the peer.
Implementations§
Source§impl<T> Party<T>
impl<T> Party<T>
Sourcepub fn sender(&self, to: usize) -> Option<&Sender<T>>
pub fn sender(&self, to: usize) -> Option<&Sender<T>>
The sender to party to, or None when to is not a party (or the
senders were closed with close_senders).
Sourcepub fn receiver(&mut self, from: usize) -> Option<&mut Receiver<T>>
pub fn receiver(&mut self, from: usize) -> Option<&mut Receiver<T>>
The receiver from party from, or None when from is not a party.
Sourcepub fn try_send_to(&self, to: usize, value: T) -> Result<(), TrySendError<T>>
pub fn try_send_to(&self, to: usize, value: T) -> Result<(), TrySendError<T>>
Sends value to party to at once, or says why it cannot be sent.
§Errors
TrySendError::Full when the channel to to is full;
TrySendError::Closed when to is not a party or its receiver is
gone. Both hold the value back.
Sourcepub fn close_senders(&mut self)
pub fn close_senders(&mut self)
Drops every sender of this party, itself included (the self-loop). The
party then only receives; its sends fail with their value. This is how
a party lets recv end.
Sourcepub async fn recv_from(&mut self, from: usize) -> Option<T>
pub async fn recv_from(&mut self, from: usize) -> Option<T>
Receives the next value from party from. Answers None when from
is not a party, or that channel ended and was drained.
Sourcepub async fn recv(&mut self) -> Option<(usize, T)>
pub async fn recv(&mut self) -> Option<(usize, T)>
Receives the next value from any party, with the index of the party
that sent it. Answers None once every channel into this party ended
and was drained.
Cancel safe: a dropped future loses no value.
Sourcepub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<(usize, T)>>
pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<(usize, T)>>
Polls for a value from any party. The receivers are polled round
robin from the one after the last that delivered, so no party is
starved, and each one that has nothing registers the waker of cx.
Sourcepub fn try_recv(&mut self) -> Result<(usize, T), TryRecvError>
pub fn try_recv(&mut self) -> Result<(usize, T), TryRecvError>
Receives a value from any party without waiting, in the order
poll_recv uses.
§Errors
TryRecvError::Empty when nothing is waiting and a value may yet
come; TryRecvError::Disconnected only when every channel ended and
was drained.