Skip to main content

OptionExt

Trait OptionExt 

Source
pub trait OptionExt<T> {
    // Required method
    fn or_not_found(self, resource_type: &str, resource_id: &str) -> Result<T>;
}
Expand description

Extension trait for Option to provide convenient error handling

§Example

use wami_core::error::{Result, OptionExt};

fn example() -> Result<String> {
    let user: Option<String> = Some("alice".to_string());
    let result = user.or_not_found("User", "alice")?;
    Ok(result)
}

Required Methods§

Source

fn or_not_found(self, resource_type: &str, resource_id: &str) -> Result<T>

Convert None to a ResourceNotFound error

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<T> OptionExt<T> for Option<T>

Source§

fn or_not_found(self, resource_type: &str, resource_id: &str) -> Result<T>

Implementors§