Skip to main content

OptionExt

Trait OptionExt 

Source
pub trait OptionExt<T> {
    // Required method
    fn or_404(self) -> Result<T>;
}
Expand description

Extension for Option: option.or_404()? turns a missing record into a 404 response.

§Examples

use ocre::{Error, OptionExt};

assert_eq!(Some(3).or_404().unwrap(), 3);
assert!(matches!(None::<i32>.or_404(), Err(Error::NotFound)));

Required Methods§

Source

fn or_404(self) -> Result<T>

The value, or Error::NotFound (404) when None.

§Errors

Error::NotFound when the option is None.

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_404(self) -> Result<T>

Implementors§