pub struct Channel<T = ()> {
pub sender: Sender<T>,
pub receiver: Receiver<T>,
}Expand description
Channel struct that combines [async_channel::Sender] and
[async_channel::Receiver] into a single struct with sender
and receiver members representing a single channel.
Fields§
§sender: Sender<T>Sender endpoint of the channel.
receiver: Receiver<T>Receiver endpoint of the channel.
Implementations§
Source§impl<T> Channel<T>
impl<T> Channel<T>
Sourcepub fn bounded(cap: usize) -> Channel<T>
pub fn bounded(cap: usize) -> Channel<T>
Creates a channel with a buffer bounded to cap messages.
Sourcepub fn oneshot() -> Channel<T>
pub fn oneshot() -> Channel<T>
Creates a oneshot channel (a bounded channel with a capacity of one message).
Sourcepub fn drain(&self) -> Result<(), TryRecvError>
pub fn drain(&self) -> Result<(), TryRecvError>
Discards all currently-buffered messages from the channel.
Sourcepub async fn recv(&self) -> Result<T, RecvError>
pub async fn recv(&self) -> Result<T, RecvError>
Receives a message, waiting asynchronously until one is available.
Sourcepub fn try_recv(&self) -> Result<T, TryRecvError>
pub fn try_recv(&self) -> Result<T, TryRecvError>
Attempts to receive a message without blocking, returning an error if the channel is empty.
Sourcepub async fn send(&self, msg: T) -> Result<(), SendError<T>>
pub async fn send(&self, msg: T) -> Result<(), SendError<T>>
Sends a message, waiting asynchronously if the channel is bounded and full.
Sourcepub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
Attempts to send a message without blocking, returning an error if the channel is full or closed.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no messages currently buffered in the channel.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Returns the number of Receiver endpoints currently connected to the channel.
Sourcepub fn sender_count(&self) -> usize
pub fn sender_count(&self) -> usize
Returns the number of Sender endpoints currently connected to the channel.
Sourcepub fn iter(&self) -> ChannelIterator<T>
pub fn iter(&self) -> ChannelIterator<T>
Returns an iterator that drains all currently-buffered messages from the channel.
Trait Implementations§
Auto Trait Implementations§
impl<T = ()> !Unpin for Channel<T>
impl<T = ()> !UnsafeUnpin for Channel<T>
impl<T> Freeze for Channel<T>
impl<T> RefUnwindSafe for Channel<T>
impl<T> Send for Channel<T>where
T: Send,
impl<T> Sync for Channel<T>where
T: Send,
impl<T> UnwindSafe for Channel<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.