Skip to main content

OptionContext

Trait OptionContext 

Source
pub trait OptionContext<T>: Sealed {
    // Required methods
    fn error(self, context: impl Display) -> Option<T>;
    fn warn(self, context: impl Display) -> Option<T>;
    fn info(self, context: impl Display) -> Option<T>;
    fn debug(self, context: impl Display) -> Option<T>;
    fn trace(self, context: impl Display) -> Option<T>;
    fn with_error<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>;
    fn with_warn<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>;
    fn with_info<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>;
    fn with_debug<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>;
    fn with_trace<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>;
}
Available on crate features tracing or log or defmt or context_stub only.
Expand description

For logging when a None is encountered.

Required Methods§

Source

fn error(self, context: impl Display) -> Option<T>

Log the context as an “error” if the Option is None.

Source

fn warn(self, context: impl Display) -> Option<T>

Log the context as an “warn” if the Option is None.

Source

fn info(self, context: impl Display) -> Option<T>

Log the context as an “info” if the Option is None.

Source

fn debug(self, context: impl Display) -> Option<T>

Log the context as an “debug” if the Option is None.

Source

fn trace(self, context: impl Display) -> Option<T>

Log the context as an “trace” if the Option is None.

Source

fn with_error<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Lazily call [f] if the Option is None and log as an “error”.

Source

fn with_warn<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Lazily call [f] if the Option is None and log as an “warn”.

Source

fn with_info<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Lazily call [f] if the Option is None and log as an “info”.

Source

fn with_debug<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Lazily call [f] if the Option is None and log as an “debug”.

Source

fn with_trace<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Lazily call [f] if the Option is None and log as an “trace”.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> OptionContext<T> for Option<T>

Available on crate features tracing or log or context_stub only.
Source§

fn error(self, context: impl Display) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn warn(self, context: impl Display) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn info(self, context: impl Display) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn debug(self, context: impl Display) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn trace(self, context: impl Display) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn with_error<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn with_warn<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn with_info<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn with_debug<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.
Source§

fn with_trace<F: FnOnce() -> D, D: Display>(self, f: F) -> Option<T>

Available on crate features tracing or log or defmt or context_stub only.

Implementors§