Skip to main content

WelpResultExt

Trait WelpResultExt 

Source
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§

Source

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.

Source

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.

Source

fn with_welp_context<S, F>(self, f: F) -> Result<T, Welp>
where S: Into<String>, F: FnOnce(&E) -> S,

Wrap the error in a Welp with a lazily-built message. The closure runs only on the Err branch and receives a shared reference to the source error.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T, E> WelpResultExt<T, E> for Result<T, E>
where E: StdError + Send + Sync + 'static,

Source§

fn welp(self) -> Result<T, Welp>

Source§

fn welp_context(self, message: impl Into<String>) -> Result<T, Welp>

Source§

fn with_welp_context<S, F>(self, f: F) -> Result<T, Welp>
where S: Into<String>, F: FnOnce(&E) -> S,

Implementors§