Trait LogError

Source
pub trait LogError<T>: Sized {
    // Required methods
    fn log_as(self, level: Level) -> Option<T>;
    fn log_with_context_as<Ctx: Fn() -> String>(
        self,
        level: Level,
        ctx: Ctx,
    ) -> Option<T>;
    fn log_as_passthrough(self, level: Level) -> Self;
    fn log_with_context_as_passthrough<Ctx: Fn() -> String>(
        self,
        level: Level,
        ctx: Ctx,
    ) -> Self;

    // Provided methods
    fn log(self) -> Option<T> { ... }
    fn log_context(self, ctx: &str) -> Option<T> { ... }
    fn log_with_context<Ctx: Fn() -> String>(self, ctx: Ctx) -> Option<T> { ... }
    fn log_context_as(self, level: Level, ctx: &str) -> Option<T> { ... }
    fn log_passthrough(self) -> Self { ... }
    fn log_context_passthrough(self, ctx: &str) -> Self { ... }
    fn log_with_context_passthrough<Ctx: Fn() -> String>(self, ctx: Ctx) -> Self { ... }
    fn log_context_as_passthrough(self, level: Level, ctx: &str) -> Self { ... }
}
Expand description

Enables logging of errors, to move forward without returning the error.

Required Methods§

Source

fn log_as(self, level: Level) -> Option<T>

Logs if there was an error and converts the result into an option

Source

fn log_with_context_as<Ctx: Fn() -> String>( self, level: Level, ctx: Ctx, ) -> Option<T>

Lazily logs if there was an error with a message at the provided log level, and converts the result into an option

Source

fn log_as_passthrough(self, level: Level) -> Self

Logs if there was an error and returns the result unchanged

Source

fn log_with_context_as_passthrough<Ctx: Fn() -> String>( self, level: Level, ctx: Ctx, ) -> Self

Lazily logs if there was an error with a message at the provided log level, and returns the result unchanged

Provided Methods§

Source

fn log(self) -> Option<T>

Logs if there was an error and converts the result into an option

Source

fn log_context(self, ctx: &str) -> Option<T>

Logs if there was an error with a message and converts the result into an option

Source

fn log_with_context<Ctx: Fn() -> String>(self, ctx: Ctx) -> Option<T>

Lazily logs if there was an error with a message and converts the result into an option

Source

fn log_context_as(self, level: Level, ctx: &str) -> Option<T>

Logs if there was an error with a message at the provided log level, and converts the result into an option

Source

fn log_passthrough(self) -> Self

Logs if there was an error and returns the result unchanged

Source

fn log_context_passthrough(self, ctx: &str) -> Self

Logs if there was an error with a message and returns the result unchanged

Source

fn log_with_context_passthrough<Ctx: Fn() -> String>(self, ctx: Ctx) -> Self

Lazily logs if there was an error with a message and returns the result unchanged

Source

fn log_context_as_passthrough(self, level: Level, ctx: &str) -> Self

Logs if there was an error with a message at the provided log level, and returns the result unchanged

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, E: Display + 'static> LogError<T> for Result<T, E>

Source§

fn log_as(self, level: Level) -> Option<T>

Source§

fn log_with_context_as<Ctx: Fn() -> String>( self, level: Level, ctx: Ctx, ) -> Option<T>

Source§

fn log_as_passthrough(self, level: Level) -> Self

Source§

fn log_with_context_as_passthrough<Ctx: Fn() -> String>( self, level: Level, ctx: Ctx, ) -> Self

Implementors§