Trait nvim_oxi_api::IntoResult

source ·
pub trait IntoResult<T> {
    type Error;

    // Required method
    fn into_result(self) -> Result<T, Self::Error>;
}
Expand description

A trait for types that can be converted into a Result.

This trait can be used to be generic over functions that can return either a T or a Result<T, E>.

§Examples

fn double<F: Fn() -> R, R: IntoResult<usize>>(
    f: F,
) -> Result<usize, R::Error> {
    f().into_result().map(|x| x * 2)
}

// `double` takes a closure whose return type is generic over `IntoResult`,
// so we don't have to return `Ok(21)`.
assert_eq!(double(|| 21), Ok(42));

Required Associated Types§

source

type Error

The error type in the returned Result.

Required Methods§

source

fn into_result(self) -> Result<T, Self::Error>

Converts the value into a Result.

Implementations on Foreign Types§

source§

impl<T, E> IntoResult<T> for Result<T, E>

§

type Error = E

source§

fn into_result(self) -> Result<T, <Result<T, E> as IntoResult<T>>::Error>

Implementors§

source§

impl<T> IntoResult<T> for T