Trait uefi::ResultExt

source ·
pub trait ResultExt<Output, ErrData: Debug> {
    // Required methods
    fn status(&self) -> Status;
    fn discard_errdata(self) -> Result<Output>;
    fn handle_warning<O>(self, op: O) -> Result<Output, ErrData>
       where O: FnOnce(Error<ErrData>) -> Result<Output, ErrData>;
}
Expand description

Extension trait which provides some convenience methods for Result.

Required Methods§

source

fn status(&self) -> Status

Extract the UEFI status from this result

source

fn discard_errdata(self) -> Result<Output>

Transform the ErrData value to ()

source

fn handle_warning<O>(self, op: O) -> Result<Output, ErrData>
where O: FnOnce(Error<ErrData>) -> Result<Output, ErrData>,

Calls op if the result contains a warning, otherwise returns the result unchanged.

By default warning statuses are treated as errors (i.e. stored in the Err variant) because they generally indicate an abnormal situation. In rare cases though it may be helpful to handle a warning. This method is similar to Result::or_else, except that op is called only when the status is a warning.

§Example
use uefi::{Result, ResultExt, Status};

// Treat a specific warning as success, propagate others as errors.
some_result.handle_warning(|err| {
    if err.status() == Status::WARN_RESET_REQUIRED {
        Ok(())
    } else {
        Err(err)
    }
})?;

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Output, ErrData: Debug> ResultExt<Output, ErrData> for Result<Output, ErrData>