pub trait CanUseChannels: HasChannelTypes + HasErrorType {
// Required methods
fn send<T>(
sender: &Self::Sender<T>,
value: T,
) -> impl Future<Output = Result<(), Self::Error>> + Send
where T: Async;
fn receive<T>(
receiver: &mut Self::Receiver<T>,
) -> impl Future<Output = Result<T, Self::Error>> + Send
where T: Async;
fn try_receive<T>(
receiver: &mut Self::Receiver<T>,
) -> Result<Option<T>, Self::Error>
where T: Async;
}Expand description
Required Methods§
Sourcefn send<T>(
sender: &Self::Sender<T>,
value: T,
) -> impl Future<Output = Result<(), Self::Error>> + Sendwhere
T: Async,
fn send<T>(
sender: &Self::Sender<T>,
value: T,
) -> impl Future<Output = Result<(), Self::Error>> + Sendwhere
T: Async,
Given a reference to Sender<T>,
send a message payload of type T over the sender.
If the receiver side of the channel has been dropped, the sending would fail and an error will be returned.
The sending operation is synchronous. This ensures the payload is
guaranteed to be in the channel queue after send() is called.
The receiving operation is expected to be asynchronous. This means
that any operation after receive() is called on the receiving end
should never execute within send().
Sourcefn receive<T>(
receiver: &mut Self::Receiver<T>,
) -> impl Future<Output = Result<T, Self::Error>> + Sendwhere
T: Async,
fn receive<T>(
receiver: &mut Self::Receiver<T>,
) -> impl Future<Output = Result<T, Self::Error>> + Sendwhere
T: Async,
Given a reference to Receiver<T>,
asynchronously receive a message payload of type T that is sent
over the sender end.
If the sender end is dropped before any value is sent, this would result
in an error in receive()
fn try_receive<T>(
receiver: &mut Self::Receiver<T>,
) -> Result<Option<T>, Self::Error>where
T: Async,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.