pub trait AsyncTxTrait<T: Unpin + Send + 'static>:
Send
+ 'static
+ Debug
+ Display
+ AsRef<ChannelShared<T>>
+ Into<AsyncSink<T>> {
// Required methods
fn try_send(&self, item: T) -> Result<(), TrySendError<T>>;
fn clone_to_vec(self, count: usize) -> Vec<Self>
where Self: Sized;
fn send<'a>(&'a self, item: T) -> SendFuture<'a, T> ⓘ;
fn send_timeout<'a>(
&'a self,
item: T,
duration: Duration,
) -> SendTimeoutFuture<'a, T, ()> ⓘ;
fn send_with_timer<'a, F, R>(
&'a self,
item: T,
fut: F,
) -> SendTimeoutFuture<'a, T, R> ⓘ
where F: Future<Output = R> + 'static;
// Provided methods
fn len(&self) -> usize { ... }
fn capacity(&self) -> Option<usize> { ... }
fn is_empty(&self) -> bool { ... }
fn is_full(&self) -> bool { ... }
fn is_disconnected(&self) -> bool { ... }
}Expand description
For writing generic code with MAsyncTx & AsyncTx
Required Methods§
Sourcefn try_send(&self, item: T) -> Result<(), TrySendError<T>>
fn try_send(&self, item: T) -> Result<(), TrySendError<T>>
Try to send message, non-blocking
Returns Ok(()) when successful.
Returns Err(TrySendError::Full) on channel full for bounded channel.
Returns Err(TrySendError::Disconnected) when all Rx dropped.
fn clone_to_vec(self, count: usize) -> Vec<Self>where
Self: Sized,
Sourcefn send<'a>(&'a self, item: T) -> SendFuture<'a, T> ⓘ
fn send<'a>(&'a self, item: T) -> SendFuture<'a, T> ⓘ
Send message. Will await when channel is full.
Returns Ok(()) on successful.
Returns Err(SendError) when all Rx is dropped.
Sourcefn send_timeout<'a>(
&'a self,
item: T,
duration: Duration,
) -> SendTimeoutFuture<'a, T, ()> ⓘ
Available on crate features tokio or async_std only.
fn send_timeout<'a>( &'a self, item: T, duration: Duration, ) -> SendTimeoutFuture<'a, T, ()> ⓘ
tokio or async_std only.Waits for a message to be sent into the channel, but only for a limited time. Will await when channel is full.
The behavior is atomic, either message sent successfully or returned on error.
Returns Ok(()) when successful.
Returns Err(SendTimeoutError::Timeout) when the operation timed out.
Returns Err(SendTimeoutError::Disconnected) when all Rx dropped.
Sourcefn send_with_timer<'a, F, R>(
&'a self,
item: T,
fut: F,
) -> SendTimeoutFuture<'a, T, R> ⓘwhere
F: Future<Output = R> + 'static,
fn send_with_timer<'a, F, R>(
&'a self,
item: T,
fut: F,
) -> SendTimeoutFuture<'a, T, R> ⓘwhere
F: Future<Output = R> + 'static,
Sends a message with a custom timer function. Will await when channel is full.
The behavior is atomic: the message is either sent successfully or returned with error.
Returns Ok(()) when successful.
Returns Err(SendTimeoutError::Timeout) if the operation timed out. The error contains the message that failed to be sent.
Returns Err(SendTimeoutError::Disconnected) if the receiver has been dropped. The error contains the message that failed to be sent.
§Argument:
fut: The sleep function. It’s possible to wrap this function with cancelable handle, you can control when to stop polling. the return value offutis ignore. We add genericRjust in order to support smol::Timer
Provided Methods§
Sourcefn capacity(&self) -> Option<usize>
fn capacity(&self) -> Option<usize>
The capacity of the channel, return None for unbounded channel.
Sourcefn is_disconnected(&self) -> bool
fn is_disconnected(&self) -> bool
Return true if the other side has closed
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.