Struct Channel
pub(crate) struct Channel<T> { pub(in ::sync::mpmc::list) head: CachePadded<Position<T>>, pub(in ::sync::mpmc::list) tail: CachePadded<Position<T>>, pub(in ::sync::mpmc::list) receivers: SyncWaker, pub(in ::sync::mpmc::list) _marker: PhantomData<T> }
Unbounded channel implemented as a linked list.
Each message sent into the channel is assigned a sequence number, i.e. an index. Indices are
represented as numbers of type usize and wrap on overflow.
Consecutive messages are grouped into blocks in order to put less pressure on the allocator and improve cache efficiency.
Fields
head: CachePadded<Position<T>>The head of the channel.
tail: CachePadded<Position<T>>The tail of the channel.
receivers: SyncWakerReceivers waiting while the channel is empty and not disconnected.
_marker: PhantomData<T>Indicates that dropping a
Channel<T>may drop messages of typeT.
Implementations
impl<T> Channel<T>
fn new() -> SelfCreates a new unbounded channel.
fn start_send(&self, token: &mut Token) -> boolAttempts to reserve a slot for sending a message.
unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T>Writes a message into the channel.
fn start_recv(&self, token: &mut Token) -> boolAttempts to reserve a slot for receiving a message.
unsafe fn read(&self, token: &mut Token) -> Result<T, ()>Reads a message from the channel.
fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>Attempts to send a message into the channel.
fn send(&self, msg: T, _deadline: Option<Instant>) -> Result<(), SendTimeoutError<T>>Sends a message into the channel.
fn try_recv(&self) -> Result<T, TryRecvError>Attempts to receive a message without blocking.
fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutError>Receives a message from the channel.
fn len(&self) -> usizeReturns the current number of messages inside the channel.
fn capacity(&self) -> Option<usize>Returns the capacity of the channel.
fn disconnect_senders(&self) -> boolDisconnects senders and wakes up all blocked receivers.
Returns
trueif this call disconnected the channel.fn disconnect_receivers(&self) -> boolDisconnects receivers.
Returns
trueif this call disconnected the channel.fn discard_all_messages(&self)Discards all messages.
This method should only be called when all receivers are dropped.
fn is_disconnected(&self) -> boolReturns
trueif the channel is disconnected.fn is_empty(&self) -> boolReturns
trueif the channel is empty.fn is_full(&self) -> boolReturns
trueif the channel is full.
Trait Implementations
impl<T> Drop for Channel<T>
fn drop(&mut self)
Auto Trait Implementations
impl<T> !Freeze for Channel<T>
impl<T> !Send for Channel<T>
impl<T> !Sync for Channel<T>
impl<T> !UnwindSafe for Channel<T>
impl<T> RefUnwindSafe for Channel<T>
where
CachePadded<Position<T>>: RefUnwindSafe + RefUnwindSafe,
PhantomData<T>: RefUnwindSafe,
impl<T> Unpin for Channel<T>
where
CachePadded<Position<T>>: Unpin + Unpin,
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for Channel<T>
where
CachePadded<Position<T>>: UnsafeUnpin + UnsafeUnpin,
PhantomData<T>: UnsafeUnpin,
Blanket Implementations
impl<T> Any for Channel<T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Channel<T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Channel<T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Channel<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for Channel<T>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for Channel<T>
impl<T, U> Into<U> for Channel<T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Channel<T>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for Channel<T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>