pub struct MpmcChannel<T> { /* private fields */ }Expand description
Multi-Producer Multi-Consumer channel with bounded capacity Uses mutex-based implementation for simplicity and correctness.
The shared state lives directly in this struct rather than behind a field
per Arc: MpmcSender/MpmcReceiver already share one handle through
Arc<MpmcChannel<T>>, so a channel costs one allocation plus the bounded
ring’s slot array. Every operation reaches the mutex, condvars, both waiter
counters and the ring through that single handle, with no second
indirection on the send/receive paths.
Implementations§
Source§impl<T> MpmcChannel<T>
impl<T> MpmcChannel<T>
Sourcepub fn new(capacity: Option<usize>) -> MpmcChannel<T>
pub fn new(capacity: Option<usize>) -> MpmcChannel<T>
Create a new MPMC channel with optional capacity
Sourcepub fn unbounded() -> MpmcChannel<T>
pub fn unbounded() -> MpmcChannel<T>
Create an unbounded channel
Sourcepub fn bounded(capacity: usize) -> MpmcChannel<T>
pub fn bounded(capacity: usize) -> MpmcChannel<T>
Create a bounded channel with given capacity
Sourcepub fn channel(capacity: Option<usize>) -> (MpmcSender<T>, MpmcReceiver<T>)
pub fn channel(capacity: Option<usize>) -> (MpmcSender<T>, MpmcReceiver<T>)
Create a channel pair for ergonomic usage
Trait Implementations§
Source§impl<T> Channel<T> for MpmcChannel<T>where
T: Send,
impl<T> Channel<T> for MpmcChannel<T>where
T: Send,
Source§fn recv(&self) -> Result<T, ChannelError>
fn recv(&self) -> Result<T, ChannelError>
Receive a value, blocking if necessary
Source§fn try_recv(&self) -> Result<T, ChannelError>
fn try_recv(&self) -> Result<T, ChannelError>
Try to receive without blocking
Source§fn send_batch(&self, values: Vec<T>) -> Result<usize, ChannelError>
fn send_batch(&self, values: Vec<T>) -> Result<usize, ChannelError>
Send multiple values in batch. Default sends each individually.
Source§fn recv_batch(&self, max_count: usize) -> Vec<T>
fn recv_batch(&self, max_count: usize) -> Vec<T>
Receive up to
max_count values in batch. Default receives individually.Source§fn stats(&self) -> Option<ChannelStatistics>
fn stats(&self) -> Option<ChannelStatistics>
Return statistics if the channel tracks them.
Source§impl<T> Consumer<T> for MpmcChannel<T>where
T: Send,
impl<T> Consumer<T> for MpmcChannel<T>where
T: Send,
Source§fn recv(&self) -> Result<T, ChannelError>
fn recv(&self) -> Result<T, ChannelError>
Receive a value, blocking until one arrives.
Source§fn try_recv(&self) -> Result<T, ChannelError>
fn try_recv(&self) -> Result<T, ChannelError>
Receive a value, or report
ChannelError::Empty rather than waiting.Source§impl<T> Producer<T> for MpmcChannel<T>where
T: Send,
impl<T> Producer<T> for MpmcChannel<T>where
T: Send,
Source§fn send(&self, value: T) -> Result<(), ChannelError>
fn send(&self, value: T) -> Result<(), ChannelError>
Send a value, blocking until there is room.
Source§fn try_send(&self, value: T) -> Result<(), ChannelError>
fn try_send(&self, value: T) -> Result<(), ChannelError>
Send a value, or report
ChannelError::Full
rather than waiting.Auto Trait Implementations§
impl<T> !Freeze for MpmcChannel<T>
impl<T> !RefUnwindSafe for MpmcChannel<T>
impl<T> Send for MpmcChannel<T>
impl<T> Sync for MpmcChannel<T>
impl<T> Unpin for MpmcChannel<T>
impl<T> UnsafeUnpin for MpmcChannel<T>
impl<T> UnwindSafe for MpmcChannel<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
Mutably borrows from an owned value. Read more