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§
Sourcefn expect_or(self) -> Result<T, Report<NotFound>>
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();Provided Methods§
Sourcefn expect_kv_dbg<K, V>(self, key: K, value: V) -> Result<T, Report<NotFound>>
fn expect_kv_dbg<K, V>(self, key: K, value: V) -> Result<T, Report<NotFound>>
Convert None into a NotFound error with key-value context where value is debug-formatted.
Sourcefn expect_by<K: Display>(self, key: K) -> Result<T, Report<NotFound>>
fn expect_by<K: Display>(self, key: K) -> Result<T, Report<NotFound>>
Convert None into a NotFound error for a missing indexed item.
Sourcefn expect_by_fn<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>>
👎Deprecated since 0.12.0: Use bigerror::OptionReport::expect_with instead
fn expect_by_fn<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>>
bigerror::OptionReport::expect_with insteadConvert None into a NotFound error with a lazily-computed index key.
Sourcefn expect_with<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>>
fn expect_with<F, K>(self, key_fn: F) -> Result<T, Report<NotFound>>
Convert None into a NotFound error with a lazily-computed index key.
Sourcefn expect_or_ctx<C>(self) -> Result<T, Report<C>>where
C: ThinContext,
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.