pub(crate) struct Channel<T> {
head: CachePadded<Position<T>>,
tail: CachePadded<Position<T>>,
receivers: SyncWaker,
_marker: PhantomData<T>,
}
mpmc_channel
#126840)Expand description
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>>
mpmc_channel
#126840)The head of the channel.
tail: CachePadded<Position<T>>
mpmc_channel
#126840)The tail of the channel.
receivers: SyncWaker
mpmc_channel
#126840)Receivers waiting while the channel is empty and not disconnected.
_marker: PhantomData<T>
mpmc_channel
#126840)Indicates that dropping a Channel<T>
may drop messages of type T
.
Implementations§
Source§impl<T> Channel<T>
impl<T> Channel<T>
Sourcepub(crate) fn new() -> Self
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn new() -> Self
mpmc_channel
#126840)Creates a new unbounded channel.
Sourcefn start_send(&self, token: &mut Token) -> bool
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
fn start_send(&self, token: &mut Token) -> bool
mpmc_channel
#126840)Attempts to reserve a slot for sending a message.
Sourcepub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T>
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) unsafe fn write(&self, token: &mut Token, msg: T) -> Result<(), T>
mpmc_channel
#126840)Writes a message into the channel.
Sourcefn start_recv(&self, token: &mut Token) -> bool
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
fn start_recv(&self, token: &mut Token) -> bool
mpmc_channel
#126840)Attempts to reserve a slot for receiving a message.
Sourcepub(crate) unsafe fn read(&self, token: &mut Token) -> Result<T, ()>
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) unsafe fn read(&self, token: &mut Token) -> Result<T, ()>
mpmc_channel
#126840)Reads a message from the channel.
Sourcepub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
mpmc_channel
#126840)Attempts to send a message into the channel.
Sourcepub(crate) fn send(
&self,
msg: T,
_deadline: Option<Instant>,
) -> Result<(), SendTimeoutError<T>>
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn send( &self, msg: T, _deadline: Option<Instant>, ) -> Result<(), SendTimeoutError<T>>
mpmc_channel
#126840)Sends a message into the channel.
Sourcepub(crate) fn try_recv(&self) -> Result<T, TryRecvError>
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn try_recv(&self) -> Result<T, TryRecvError>
mpmc_channel
#126840)Attempts to receive a message without blocking.
Sourcepub(crate) fn recv(
&self,
deadline: Option<Instant>,
) -> Result<T, RecvTimeoutError>
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn recv( &self, deadline: Option<Instant>, ) -> Result<T, RecvTimeoutError>
mpmc_channel
#126840)Receives a message from the channel.
Sourcepub(crate) fn len(&self) -> usize
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn len(&self) -> usize
mpmc_channel
#126840)Returns the current number of messages inside the channel.
Sourcepub(crate) fn capacity(&self) -> Option<usize>
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn capacity(&self) -> Option<usize>
mpmc_channel
#126840)Returns the capacity of the channel.
Sourcepub(crate) fn disconnect_senders(&self) -> bool
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn disconnect_senders(&self) -> bool
mpmc_channel
#126840)Disconnects senders and wakes up all blocked receivers.
Returns true
if this call disconnected the channel.
Sourcepub(crate) fn disconnect_receivers(&self) -> bool
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn disconnect_receivers(&self) -> bool
mpmc_channel
#126840)Disconnects receivers.
Returns true
if this call disconnected the channel.
Sourcefn discard_all_messages(&self)
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
fn discard_all_messages(&self)
mpmc_channel
#126840)Discards all messages.
This method should only be called when all receivers are dropped.
Sourcepub(crate) fn is_disconnected(&self) -> bool
🔬This is a nightly-only experimental API. (mpmc_channel
#126840)
pub(crate) fn is_disconnected(&self) -> bool
mpmc_channel
#126840)Returns true
if the channel is disconnected.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Channel<T>
impl<T> RefUnwindSafe for Channel<T>where
T: RefUnwindSafe,
impl<T> !Send for Channel<T>
impl<T> !Sync for Channel<T>
impl<T> Unpin for Channel<T>where
T: Unpin,
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
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties
)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties
)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)[Self]
. Read more