pub trait Context {
    // Required methods
    fn context<S: Into<String>>(self, msg: S) -> Self;
    fn with_context<F, S>(self, f: F) -> Self
       where F: FnOnce() -> S,
             S: Into<String>;
    fn color_context<S: Into<String>>(self, color: Color, msg: S) -> Self;
    fn with_color_context<F, S>(self, f: F) -> Self
       where F: FnOnce() -> (Color, S),
             S: Into<String>;
}
Expand description

A trait for adding context to an error that will be printed along with the error. Contexts are useful for adding things such as hints (i.e. try –help), or additional information such as the path name on a PermissionDenied error, etc.

NOTE: all contexts print without a trailing newline. This allows a context to print to the same line in different formats (colors, etc.). If a trailing newline is required, you should add it manually.

Required Methods§

source

fn context<S: Into<String>>(self, msg: S) -> Self

A simple context

source

fn with_context<F, S>(self, f: F) -> Selfwhere F: FnOnce() -> S, S: Into<String>,

A context that is evaluated lazily when called. This is useful if building the context is expensive or allocates

source

fn color_context<S: Into<String>>(self, color: Color, msg: S) -> Self

A simple context that will color the output

NOTE: The color is reset at the end of this context even if there is no trailing newline. This allows you to chain multiple contexts on the same line where only part of the context is colored.

source

fn with_color_context<F, S>(self, f: F) -> Selfwhere F: FnOnce() -> (Color, S), S: Into<String>,

A context that will color the output and that is evaluated lazily when called. This is useful if building the context is expensive or allocates

NOTE: The color is reset at the end of this context even if there is no trailing newline. This allows you to chain multiple contexts on the same line where only part of the context is colored.

Implementations on Foreign Types§

source§

impl<T> Context for StdResult<T, CliError>

source§

fn context<S: Into<String>>(self, msg: S) -> Self

source§

fn color_context<S: Into<String>>(self, color: Color, msg: S) -> Self

source§

fn with_context<F, S>(self, f: F) -> Selfwhere F: FnOnce() -> S, S: Into<String>,

source§

fn with_color_context<F, S>(self, f: F) -> Selfwhere F: FnOnce() -> (Color, S), S: Into<String>,

Implementors§