[][src]Trait user_error::UFE

pub trait UFE: Error {
    fn summary(&self) -> String { ... }
fn reasons(&self) -> Option<Vec<String>> { ... }
fn helptext(&self) -> Option<String> { ... }
fn pretty_summary(&self) -> String { ... }
fn pretty_reasons(&self) -> Option<String> { ... }
fn pretty_helptext(&self) -> Option<String> { ... }
fn print(&self) { ... }
fn print_and_exit(&self) { ... } }

You can implement UFE on your error types pretty print them. The default implementation will print Error: <your error .to_string()> followed by a list of reasons that are any errors returned by .source() You should only override the summary, reasons and helptext functions. The pretty print versions of these are used by print(), print_and_exit() and contain the formatting. If you wish to change the formatting you should update it with the formatting functions.

Provided methods

fn summary(&self) -> String

Returns a summary of the error. This will be printed in red, prefixed by "Error: ", at the top of the error message. This is not Optional.

fn reasons(&self) -> Option<Vec<String>>

Returns a vector of Strings that will be listed as bullet points below the summary. By default, lists any errors returned by .source() recursively.

fn helptext(&self) -> Option<String>

Returns help text that is listed below the reasons in a muted fashion. Useful for additional details, or suggested next steps.

fn pretty_summary(&self) -> String

Convenience function that converts the summary into pretty String. You shouldn't implement this.

fn pretty_reasons(&self) -> Option<String>

Convenience function that converts the reasons into pretty String. You shouldn't implement this.

fn pretty_helptext(&self) -> Option<String>

Convenience function that converts the help text into pretty String. You shouldn't implement this.

fn print(&self)

Prints the formatted error.

Example

use user_error::{UserFacingError, UFE};
UserFacingError::new("File failed to open")
        .reason("File not found")
        .help("Try: touch file.txt")
        .print();

fn print_and_exit(&self)

Convenience function that pretty prints the error and exits the program.

Example

use user_error::{UserFacingError, UFE};
UserFacingError::new("File failed to open")
        .reason("File not found")
        .help("Try: touch file.txt")
        .print_and_exit();
Loading content...

Implementors

impl UFE for UserFacingError[src]

Loading content...