Skip to main content

OptionExt

Trait OptionExt 

Source
pub trait OptionExt<T> {
    // Required methods
    fn ok_or_cbkp_error(
        self,
        code: ErrorCode,
        message: impl Into<String>,
    ) -> Result<T, Error>;
    fn ok_or_error(self, error: Error) -> Result<T, Error>;
}
Expand description

Extension trait for Option<T> providing panic-safe unwrapping with context

Required Methods§

Source

fn ok_or_cbkp_error( self, code: ErrorCode, message: impl Into<String>, ) -> Result<T, Error>

Unwrap an option safely, returning a structured error with context if None

§Errors

Returns the specified error code and message if the option is None.

Source

fn ok_or_error(self, error: Error) -> Result<T, Error>

Unwrap an option safely with a specific error context

§Errors

Returns the provided error if the option is None.

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

Source§

fn ok_or_cbkp_error( self, code: ErrorCode, message: impl Into<String>, ) -> Result<T, Error>

Source§

fn ok_or_error(self, error: Error) -> Result<T, Error>

Implementors§