Trait LogError

Source
pub trait LogError<T, E>: Sized {
    // Required method
    fn log_level_with<F: FnOnce(E) -> String>(
        self,
        level: Level,
        cb: F,
    ) -> Option<T>;

    // Provided methods
    fn log_error_with<F: FnOnce(E) -> String>(self, cb: F) -> Option<T> { ... }
    fn log_warn_with<F: FnOnce(E) -> String>(self, cb: F) -> Option<T> { ... }
    fn log_error(self, msg: &str) -> Option<T>
       where E: Display { ... }
    fn log_error_detail(self, msg: &str) -> Option<T>
       where E: Debug { ... }
    fn log_warn(self, msg: &str) -> Option<T>
       where E: Display { ... }
    fn log_warn_detail(self, msg: &str) -> Option<T>
       where E: Debug { ... }
}
Expand description

Trait to log the error result, there are impls for Result and Option by default.

Required Methods§

Source

fn log_level_with<F: FnOnce(E) -> String>( self, level: Level, cb: F, ) -> Option<T>

log the error with specific log-level and format handler

Provided Methods§

Source

fn log_error_with<F: FnOnce(E) -> String>(self, cb: F) -> Option<T>

log a error message with specific format handler

Source

fn log_warn_with<F: FnOnce(E) -> String>(self, cb: F) -> Option<T>

log a warn message with specific format handler

Source

fn log_error(self, msg: &str) -> Option<T>
where E: Display,

log the error with specific prefix

Source

fn log_error_detail(self, msg: &str) -> Option<T>
where E: Debug,

log the error with specific prefix in a detailed format

Source

fn log_warn(self, msg: &str) -> Option<T>
where E: Display,

log the error with specific prefix as a warn message

Source

fn log_warn_detail(self, msg: &str) -> Option<T>
where E: Debug,

log the error with specific prefix in a detailed format as a warn message

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> LogError<T, &'static str> for Option<T>

Implements LogError for Option

Source§

fn log_level_with<F: FnOnce(&'static str) -> String>( self, level: Level, cb: F, ) -> Option<T>

Source§

impl<T, E> LogError<T, E> for Result<T, E>

Implements LogError for Result

Source§

fn log_level_with<F: FnOnce(E) -> String>( self, level: Level, cb: F, ) -> Option<T>

Implementors§