Skip to main content

Party

Struct Party 

Source
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>

Source

pub fn index(&self) -> usize

This party’s index in the mesh.

Source

pub fn parties(&self) -> usize

How many parties the mesh has, this one included.

Source

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).

Source

pub fn receiver(&mut self, from: usize) -> Option<&mut Receiver<T>>

The receiver from party from, or None when from is not a party.

Source

pub async fn send_to(&self, to: usize, value: T) -> Result<(), SendError<T>>

Sends value to party to, waiting for room in the channel to it.

§Errors

A SendError holding the value when to is not a party or its receiver is gone.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn into_parts(self) -> (Vec<Sender<T>>, Vec<Receiver<T>>)

Takes the party apart: its senders and its receivers, indexed by peer.

Trait Implementations§

Source§

impl<T> Debug for Party<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Party<T>

§

impl<T> RefUnwindSafe for Party<T>

§

impl<T> Send for Party<T>
where T: Send,

§

impl<T> Sync for Party<T>
where T: Send,

§

impl<T> Unpin for Party<T>

§

impl<T> UnsafeUnpin for Party<T>

§

impl<T> UnwindSafe for Party<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.