Skip to main content

ChannelSpec

Trait ChannelSpec 

Source
pub trait ChannelSpec:
    Sealed
    + Sized
    + 'static {
    type Sender<T: Debug + Send + 'static>: Sink<T, Error = Self::SendError> + Debug + Unpin + Sized;
    type Receiver<T: Debug + Send + 'static>: Stream<Item = T> + Debug + Unpin + Send + Sized;
    type SendError: Error;

    // Required methods
    fn raw_channel<T: Debug + Send + 'static>(
        self,
    ) -> (Self::Sender<T>, Self::Receiver<T>);
    fn close_receiver<T: Debug + Send + 'static>(rx: &mut Self::Receiver<T>);

    // Provided method
    fn new_mq<T>(
        self,
        runtime: DynTimeProvider,
        account: &Account,
    ) -> Result<(Sender<T, Self>, Receiver<T, Self>)>
       where T: HasMemoryCost + Debug + Send + 'static { ... }
}
Expand description

Specification for a communication channel

Implemented for MpscSpec and MpscUnboundedSpec.

Required Associated Types§

Source

type Sender<T: Debug + Send + 'static>: Sink<T, Error = Self::SendError> + Debug + Unpin + Sized

The sending Sink for items of type T.

Source

type Receiver<T: Debug + Send + 'static>: Stream<Item = T> + Debug + Unpin + Send + Sized

The receiving Stream for items of type T.

Source

type SendError: Error

The error type <Receiver<_> as Stream>::Error.

(For this trait to be implemented, it is not allowed to depend on T.)

Required Methods§

Source

fn raw_channel<T: Debug + Send + 'static>( self, ) -> (Self::Sender<T>, Self::Receiver<T>)

Create a new raw channel as specified by self

Source

fn close_receiver<T: Debug + Send + 'static>(rx: &mut Self::Receiver<T>)

Close the receiver, preventing further sends

This should ensure that only a smallish bounded number of further items can be sent, before errors start being returned.

Provided Methods§

Source

fn new_mq<T>( self, runtime: DynTimeProvider, account: &Account, ) -> Result<(Sender<T, Self>, Receiver<T, Self>)>
where T: HasMemoryCost + Debug + Send + 'static,

Create a new channel, based on the spec self, that participates in the memory quota

See the module-level docs for an example.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§