Skip to main content

Channel

Trait Channel 

Source
pub trait Channel<T>: Send + Sync {
Show 13 methods // Required methods fn send(&self, value: T) -> Result<(), ChannelError>; fn try_send(&self, value: T) -> Result<(), ChannelError>; fn recv(&self) -> Result<T, ChannelError>; fn try_recv(&self) -> Result<T, ChannelError>; fn is_empty(&self) -> bool; fn is_full(&self) -> bool; fn capacity(&self) -> Option<usize>; // Provided methods fn send_batch(&self, values: Vec<T>) -> Result<usize, ChannelError> { ... } fn recv_batch(&self, max_count: usize) -> Vec<T> { ... } fn close(&self) { ... } fn is_closed(&self) -> bool { ... } fn len(&self) -> usize { ... } fn stats(&self) -> Option<ChannelStatistics> { ... }
}
Expand description

Trait for unified channel behavior following Interface Segregation Principle

Required Methods§

Source

fn send(&self, value: T) -> Result<(), ChannelError>

Send a value, blocking if necessary

Source

fn try_send(&self, value: T) -> Result<(), ChannelError>

Try to send without blocking

Source

fn recv(&self) -> Result<T, ChannelError>

Receive a value, blocking if necessary

Source

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

Try to receive without blocking

Source

fn is_empty(&self) -> bool

Check if channel is empty

Source

fn is_full(&self) -> bool

Check if channel is full

Source

fn capacity(&self) -> Option<usize>

Get the capacity of the channel

Provided Methods§

Source

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>

Receive up to max_count values in batch. Default receives individually.

Source

fn close(&self)

Close the channel. Default: no-op (channels that support close override).

Source

fn is_closed(&self) -> bool

Check if channel is closed. Default: false.

Source

fn len(&self) -> usize

Current number of buffered items. Default: 0.

Source

fn stats(&self) -> Option<ChannelStatistics>

Return statistics if the channel tracks them.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Channel<T> for MpmcChannel<T>
where T: Send,