OptionReport

Trait OptionReport 

Source
pub trait OptionReport<T>
where Self: Sized,
{ // Required methods fn expect_or(self) -> Result<T, Report<NotFound>>; fn expect_kv<K, V>(self, key: K, value: V) -> Result<T, Report<NotFound>> where K: Display, V: Display; fn expect_field(self, field: &'static str) -> Result<T, Report<NotFound>>; // Provided methods fn expect_kv_dbg<K, V>( self, key: K, value: V, ) -> Result<T, Report<NotFound>> where K: Display, V: Debug { ... } fn expect_by<K: Display>(self, key: K) -> Result<T, Report<NotFound>> { ... } fn expect_by_fn<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>> where K: Display, F: FnOnce() -> K { ... } fn expect_with<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>> where K: Display, F: FnOnce() -> K { ... } fn expect_or_ctx<C>(self) -> Result<T, Report<C>> where C: ThinContext { ... } }
Expand description

Extension trait for Option<T> that provides methods to convert None into error reports.

This trait allows you to easily convert Option values into Result<T, Report<NotFound>> with descriptive error messages.

Required Methods§

Source

fn expect_or(self) -> Result<T, Report<NotFound>>

Convert None into a NotFound error with type information.

This method transforms an Option<T> into a Result<T, Report<NotFound>>, automatically attaching the type information of T to provide context about what was expected but not found.

§Example
use bigerror::{OptionReport, NotFound, Report};

let maybe_value: Option<String> = None;
let result: Result<String, Report<NotFound>> = maybe_value.expect_or();
Source

fn expect_kv<K, V>(self, key: K, value: V) -> Result<T, Report<NotFound>>
where K: Display, V: Display,

Convert None into a NotFound error with key-value context.

Source

fn expect_field(self, field: &'static str) -> Result<T, Report<NotFound>>

Convert None into a NotFound error for a missing field.

Provided Methods§

Source

fn expect_kv_dbg<K, V>(self, key: K, value: V) -> Result<T, Report<NotFound>>
where K: Display, V: Debug,

Convert None into a NotFound error with key-value context where value is debug-formatted.

Source

fn expect_by<K: Display>(self, key: K) -> Result<T, Report<NotFound>>

Convert None into a NotFound error for a missing indexed item.

Source

fn expect_by_fn<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>>
where K: Display, F: FnOnce() -> K,

👎Deprecated since 0.12.0: Use bigerror::OptionReport::expect_with instead

Convert None into a NotFound error with a lazily-computed index key.

Source

fn expect_with<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>>
where K: Display, F: FnOnce() -> K,

Convert None into a NotFound error with a lazily-computed index key.

Source

fn expect_or_ctx<C>(self) -> Result<T, Report<C>>
where C: ThinContext,

Convert None into a NotFound That is then propagated to a ThinContext

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.

Implementations on Foreign Types§

Source§

impl<T> OptionReport<T> for Option<T>

Source§

fn expect_or(self) -> Result<T, Report<NotFound>>

Source§

fn expect_kv<K, V>(self, key: K, value: V) -> Result<T, Report<NotFound>>
where K: Display, V: Display,

Source§

fn expect_field(self, field: &'static str) -> Result<T, Report<NotFound>>

Implementors§