[][src]Struct user_error::UserFacingError

pub struct UserFacingError<S: UFEState> { /* fields omitted */ }

The eponymous struct.

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .helptext("Make sure foo.txt exists");

Methods

impl UserFacingError<Start>[src]

pub fn new(s: &str) -> UserFacingError<Start>[src]

This is how users create a new User Facing Error. The value passed to new() will be used as an error summary. Error summaries are displayed first, prefixed by 'Error: '.

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open");

pub fn print(&self)[src]

Prints the error

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open");
err.print();

pub fn print_and_exit(&self) -> ![src]

Prints the error and then exits the program

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open");
err.print_and_exit();

pub fn reason(self, r: &str) -> UserFacingError<Reason>[src]

Add a reason to the UserFacingError. Reasons are displayed in a bulleted list below the summary.

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .reason("Directory cannot be entered");

pub fn helptext(self, h: &str) -> UserFacingError<HelpText>[src]

Add help text to the error. Help text is displayed last, in a muted fashion. Once you add help text you cannot add additional reasons.

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .helptext("Check if the file exists.");

This will not compile

This example deliberately fails to compile
let err = UserFacingError::new("File failed to open")
                            .helptext("Check if the file exists.")
                            .reason("File not found");

impl UserFacingError<HelpText>[src]

pub fn print(&self)[src]

Prints the error

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .helptext("Check that it exists");
err.print();

pub fn print_and_exit(&self) -> ![src]

Prints the error and then exits the program

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .helptext("Check that it exists");
err.print_and_exit();

impl UserFacingError<Reason>[src]

pub fn from(error: &dyn Error) -> Self[src]

Allows the creation of a UserFacingError from a Error. Checks the source() of the error and will list underlying errors as reasons for the error. You may add additional reasons and helptext.

Example

use user_error::UserFacingError;

let ioe = std::io::Error::new(std::io::ErrorKind::Other, "Error");
let ufe = UserFacingError::from(&ioe);    let ioe = std::io::Error::new(std::io::ErrorKind::Other, "Error");          
let ufe = ufe.reason("No good reason");

pub fn print(&self)[src]

Prints the error

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found");
err.print();

pub fn print_and_exit(&self) -> ![src]

Prints the error and then exits the program

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found");
err.print_and_exit();

pub fn reason(self, r: &str) -> Self[src]

Add a reason to the UserFacingError. Reasons are displayed in a bulleted list below the summary.

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .reason("Directory cannot be entered");

pub fn helptext(self, h: &str) -> UserFacingError<ReasonsAndHelp>[src]

Add help text to the error. Help text is displayed last, in a muted fashion. Once you add help text you cannot add additional reasons.

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .helptext("Check if the file exists.");

This will not compile

This example deliberately fails to compile
let err = UserFacingError::new("File failed to open")
                            .helptext("Check if the file exists.")
                            .reason("File not found");

impl UserFacingError<ReasonsAndHelp>[src]

pub fn print(&self)[src]

Prints the error

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .helptext("Make sure the file exists");
err.print();

pub fn print_and_exit(&self) -> ![src]

Prints the error and then exits the program

Example

use user_error::UserFacingError;

let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .helptext("Make sure the file exists");
err.print_and_exit();

Trait Implementations

impl<S: Debug + UFEState> Debug for UserFacingError<S>[src]

impl Display for UserFacingError<Start>[src]

impl Display for UserFacingError<HelpText>[src]

impl Display for UserFacingError<Reason>[src]

impl Display for UserFacingError<ReasonsAndHelp>[src]

impl Error for UserFacingError<Start>[src]

impl Error for UserFacingError<HelpText>[src]

impl Error for UserFacingError<Reason>[src]

impl Error for UserFacingError<ReasonsAndHelp>[src]

Auto Trait Implementations

impl<S> Send for UserFacingError<S> where
    S: Send

impl<S> Sync for UserFacingError<S> where
    S: Sync

impl<S> Unpin for UserFacingError<S> where
    S: Unpin

impl<S> UnwindSafe for UserFacingError<S> where
    S: UnwindSafe

impl<S> RefUnwindSafe for UserFacingError<S> where
    S: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]