pub trait FallibleExt<T> {
// Required methods
fn send_lossy(&self, msg: T) -> bool;
fn request<R, F>(
&self,
make_msg: F,
) -> impl Future<Output = Option<R>> + Send
where R: Send,
F: FnOnce(Sender<R>) -> T + Send;
fn request_or<R, F>(
&self,
make_msg: F,
default: R,
) -> impl Future<Output = R> + Send
where R: Send,
F: FnOnce(Sender<R>) -> T + Send;
fn request_or_default<R, F>(
&self,
make_msg: F,
) -> impl Future<Output = R> + Send
where R: Default + Send,
F: FnOnce(Sender<R>) -> T + Send;
}Expand description
Extension trait for channel operations that may fail due to disconnection.
Use these methods when the receiver may be dropped during shutdown and you want to handle that gracefully rather than panicking.
Required Methods§
Sourcefn send_lossy(&self, msg: T) -> bool
fn send_lossy(&self, msg: T) -> bool
Send a message, returning true if successful.
Use this for fire-and-forget messages where the receiver may have been dropped during shutdown. The return value can be ignored if the caller doesn’t need to know whether the send succeeded.
Sourcefn request<R, F>(&self, make_msg: F) -> impl Future<Output = Option<R>> + Send
fn request<R, F>(&self, make_msg: F) -> impl Future<Output = Option<R>> + Send
Send a request message containing a oneshot responder and await the response.
Returns None if:
- The receiver has been dropped (send fails)
- The responder is dropped without sending (receive fails)
§Example
let dialable: Option<Vec<PublicKey>> = sender
.request(|tx| Message::Dialable { responder: tx })
.await;Sourcefn request_or<R, F>(
&self,
make_msg: F,
default: R,
) -> impl Future<Output = R> + Send
fn request_or<R, F>( &self, make_msg: F, default: R, ) -> impl Future<Output = R> + Send
Send a request and return the provided default on failure.
This is a convenience wrapper around request for cases
where you have a sensible default value.
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.