Struct UnboundedChannel

Source
pub struct UnboundedChannel<T> { /* private fields */ }
Expand description

An unsynchronized (!Sync), asynchronous and unbounded channel.

Implementations§

Source§

impl<T> UnboundedChannel<T>

Source

pub fn with_initial_capacity(initial: usize) -> Self

Returns a new unbounded channel with pre-allocated initial capacity.

Source

pub fn split( &mut self, ) -> (UnboundedSenderRef<'_, T>, UnboundedReceiverRef<'_, T>)

Splits the channel into borrowing UnboundedSenderRef and UnboundedReceiverRef handles.

§Examples
use async_unsync::unbounded;

// must use a non-temporary binding for the channel
let mut chan = unbounded::channel();
let (tx, mut rx) = chan.split();
tx.send(1).unwrap();

// dropping the handles will close the channel
drop((tx, rx));
assert!(chan.is_closed());

// ...but the queued value can still be received
assert_eq!(chan.try_recv(), Ok(1));
assert!(chan.try_recv().is_err());
Source

pub fn into_split(self) -> (UnboundedSender<T>, UnboundedReceiver<T>)

Splits the channel into owning UnboundedSender and UnboundedReceiver handles.

This requires one additional allocation over split, but avoids potential lifetime restrictions, since the returned handles are valid for the 'static lifetime, meaning they can be used in spawned (local) tasks.

Source

pub fn into_deque(self) -> VecDeque<T>

Converts into the underlying VecDeque container.

Source

pub fn len(&self) -> usize

Returns the number of queued elements.

Source

pub fn close(&self)

Closes the channel, ensuring that all subsequent sends will fail.

Source

pub fn is_closed(&self) -> bool

Returns true if the channel is closed.

Source

pub fn is_empty(&self) -> bool

Returns true if the channel is empty.

Source

pub fn try_recv(&self) -> Result<T, TryRecvError>

Receives an element through the channel.

§Errors

Fails, if the channel is empty or disconnected.

Source

pub fn poll_recv(&self, cx: &mut Context<'_>) -> Poll<Option<T>>

Polls the channel, resolving if an element was received or the channel is closed, ignoring whether there are any remaining Sender(s) or not.

Source

pub async fn recv(&self) -> Option<T>

Receives an element through the channel.

§Errors

Fails, if the channel is closed (i.e., all senders have been dropped).

Source

pub fn send(&self, elem: T) -> Result<(), SendError<T>>

Sends a value through the channel.

§Errors

Fails, if the queue is closed.

Trait Implementations§

Source§

impl<T> Debug for UnboundedChannel<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> FromIterator<T> for UnboundedChannel<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for UnboundedChannel<T>

§

impl<T> !RefUnwindSafe for UnboundedChannel<T>

§

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

§

impl<T> !Sync for UnboundedChannel<T>

§

impl<T> Unpin for UnboundedChannel<T>
where T: Unpin,

§

impl<T> UnwindSafe for UnboundedChannel<T>
where T: UnwindSafe,

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.

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.