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§
Sourcefn with_context<F, S>(self, f: F) -> Self
fn with_context<F, S>(self, f: F) -> Self
A context that is evaluated lazily when called. This is useful if building the context is expensive or allocates
Sourcefn color_context<S: Into<String>>(self, color: Color, msg: S) -> Self
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.
Sourcefn with_color_context<F, S>(self, f: F) -> Self
fn with_color_context<F, S>(self, f: F) -> Self
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.
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.