Skip to main content

WelpOptionExt

Trait WelpOptionExt 

Source
pub trait WelpOptionExt<T>: Sized {
    // Required methods
    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() -> S;
}
Expand description

Extension trait on Option for converting None into a Welp.

Bring this into scope via use oopsie::prelude::* (or use oopsie_core::WelpOptionExt).

use oopsie_core::{Welp, WelpOptionExt as _};

fn first_word(s: &str) -> Result<&str, Welp> {
    s.split_whitespace().next().welp_context("string is empty")
}

Required Methods§

Source

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

Convert None into 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 Some branch. Use with_welp_context when the message is built from a non-trivial expression that should only run on None.

Source

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

Convert None into a Welp with a lazily-built message. The closure runs only on the None branch.

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> WelpOptionExt<T> for Option<T>

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() -> S,

Implementors§