pub trait WelpResultExt<T, E>: Sized {
// Required methods
fn welp(self) -> Result<T, Welp>;
fn welp_context(self, message: impl Into<String>) -> Result<T, Welp>;
fn with_welp_context<S, F>(self, f: F) -> Result<T, Welp>
where S: Into<String>,
F: FnOnce(&E) -> S;
}Expand description
Extension trait on Result for attaching a string message that produces
a Welp.
Bring this into scope via use oopsie::prelude::* (or use oopsie_core::WelpResultExt).
use oopsie_core::{Welp, WelpResultExt as _};
fn read(path: &str) -> Result<String, Welp> {
std::fs::read_to_string(path).welp_context("could not read")
}Required Methods§
Sourcefn welp(self) -> Result<T, Welp>
fn welp(self) -> Result<T, Welp>
Convert the error into a Welp with no user message — the kind of
message-free ?-style conversion anyhow/eyre give you for free. The
resulting Welp’s Display delegates to the
source’s, and the source stays reachable through
Error::source. Reach for
welp_context instead when a string adds
information the source doesn’t already carry.
Sourcefn welp_context(self, message: impl Into<String>) -> Result<T, Welp>
fn welp_context(self, message: impl Into<String>) -> Result<T, Welp>
Wrap the error in a Welp with the given message.
Note: the message argument is evaluated at the call site per Rust’s
eager-argument rules — welp_context(format!(...)) allocates the
formatted String even on the Ok branch. Use with_welp_context
when the message is built from a non-trivial expression that should
only run on Err.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".