pub trait OptionExt<T> {
    // Required methods
    fn unwrap_or_log(self) -> T;
    fn expect_or_log(self, msg: &str) -> T;
    fn unwrap_none_or_log(self)
       where T: Debug;
    fn expect_none_or_log(self, msg: &str)
       where T: Debug;
}
Expand description

Extension trait for Option types.

Required Methods§

source

fn unwrap_or_log(self) -> T

Moves the value v out of the Option<T> if it is [Some(v)].

In general, because this function may panic, its use is discouraged. Instead, prefer to use pattern matching and handle the None case explicitly.

§Panics

Panics if the self value equals None, logging an error message to a tracing::Subscriber at an [ERROR] level.

source

fn expect_or_log(self, msg: &str) -> T

Unwraps an option, yielding the content of a Some.

§Panics

Panics if the value is a None, logging the passed message to a tracing::Subscriber at an [ERROR] level.

source

fn unwrap_none_or_log(self)
where T: Debug,

Unwraps an option, expecting None and returning nothing.

§Panics

Panics if the value is a Some, logging a message derived from the Some’s value to a tracing::Subscriber at an [ERROR] level.

source

fn expect_none_or_log(self, msg: &str)
where T: Debug,

Unwraps an option, expecting None and returning nothing.

§Panics

Panics if the value is a Some, logging the passed message and the content of the Some to a tracing::Subscriber at an [ERROR] level.

Implementations on Foreign Types§

source§

impl<T> OptionExt<T> for Option<T>

source§

fn unwrap_or_log(self) -> T

source§

fn expect_or_log(self, msg: &str) -> T

source§

fn unwrap_none_or_log(self)
where T: Debug,

source§

fn expect_none_or_log(self, msg: &str)
where T: Debug,

Implementors§