OkOrNotFound

Trait OkOrNotFound 

Source
pub trait OkOrNotFound {
    type T;

    // Required method
    fn ok_or_not_found<B>(self) -> Result<Self::T, NotFoundError<B>>;
}
Expand description

An extension trait for Option<T> to convert it to Result<T, NotFoundError<AnotherType>>

Useful in places where you need NotFoundError<AnotherType> instead of NotFoundError<T>.

§Examples

pub fn get_root(path: &Path) -> Result<&Path, NotFoundError<WorkspaceRoot>> {
     find_root(path).ok_or_not_found()
}

§See also

  • Require: Trait for converting Option<T> to Result<T, NotFoundError<T>>
  • require: Function to convert Option<T> to Result<T, NotFoundError<T>>

Required Associated Types§

Source

type T

Required Methods§

Source

fn ok_or_not_found<B>(self) -> Result<Self::T, NotFoundError<B>>

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

Source§

type T = T

Source§

fn ok_or_not_found<B>(self) -> Result<Self::T, NotFoundError<B>>

Implementors§