pub struct UserFacingError { /* private fields */ }
Expand description
The eponymous struct. You can create a new one from using user_error::UserFacingError::new() however I recommend you use your own error types and have them implement UFE instead of using UserFacingError directly. This is more of an example type, or a way to construct a pretty messages without implementing your own error type.
Implementations§
Source§impl UserFacingError
impl UserFacingError
Sourcepub fn new<S: Into<String>>(summary: S) -> UserFacingError
pub fn new<S: Into<String>>(summary: S) -> UserFacingError
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
let err = UserFacingError::new("File failed to open");
Sourcepub fn update<S: Into<String>>(&mut self, summary: S)
pub fn update<S: Into<String>>(&mut self, summary: S)
Replace the error summary.
§Example
let mut err = UserFacingError::new("File failed to open");
err.update("Failed Task");
Sourcepub fn push<S: Into<String>>(&mut self, new_summary: S)
pub fn push<S: Into<String>>(&mut self, new_summary: S)
Replace the error summary and add the previous error summary to the list of reasons
§Example
let mut err = UserFacingError::new("File failed to open");
err.push("Failed Task");
Sourcepub fn reason<S: Into<String>>(self, reason: S) -> UserFacingError
pub fn reason<S: Into<String>>(self, reason: S) -> UserFacingError
Add a reason to the UserFacingError. Reasons are displayed in a bulleted list below the summary, in the reverse order they were added.
§Example
let err = UserFacingError::new("File failed to open")
.reason("File not found")
.reason("Directory cannot be entered");
Sourcepub fn clear_reasons(&mut self)
pub fn clear_reasons(&mut self)
Clears all reasons from a UserFacingError.
§Example
let mut err = UserFacingError::new("File failed to open")
.reason("File not found")
.reason("Directory cannot be entered");
err.clear_reasons();
Sourcepub fn help<S: Into<String>>(self, helptext: S) -> UserFacingError
pub fn help<S: Into<String>>(self, helptext: S) -> UserFacingError
Add help text to the error. Help text is displayed last, in a muted fashion.
§Example
let err = UserFacingError::new("File failed to open")
.reason("File not found")
.help("Check if the file exists.");
Sourcepub fn clear_helptext(&mut self)
pub fn clear_helptext(&mut self)
Clears all the help text from a UserFacingError.
§Example
let mut err = UserFacingError::new("File failed to open")
.reason("File not found")
.reason("Directory cannot be entered")
.help("Check if the file exists.");
err.clear_helptext();
Trait Implementations§
Source§impl Debug for UserFacingError
impl Debug for UserFacingError
Source§impl Display for UserFacingError
impl Display for UserFacingError
Source§impl Error for UserFacingError
impl Error for UserFacingError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<&dyn Error> for UserFacingError
Allows you to create UserFacingErrors From std Errors.
You should really just implement UFE for your error type, but if you wanted
to convert before quitting so you could add help text of something you can
use this.
impl From<&dyn Error> for UserFacingError
Allows you to create UserFacingErrors From std Errors. You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.
Source§fn from(error: &dyn Error) -> UserFacingError
fn from(error: &dyn Error) -> UserFacingError
Source§impl From<Box<dyn Error>> for UserFacingError
Allows you to create UserFacingErrors From std Errors.
You should really just implement UFE for your error type, but if you wanted
to convert before quitting so you could add help text of something you can
use this.
impl From<Box<dyn Error>> for UserFacingError
Allows you to create UserFacingErrors From std Errors. You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.
Source§impl From<Error> for UserFacingError
Allows you to create UserFacingErrors From std::io::Error for convenience
You should really just implement UFE for your error type, but if you wanted
to convert before quitting so you could add help text of something you can
use this.
impl From<Error> for UserFacingError
Allows you to create UserFacingErrors From std::io::Error for convenience You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.
Source§fn from(error: Error) -> UserFacingError
fn from(error: Error) -> UserFacingError
Source§impl<T: Debug> From<Result<T, Box<dyn Error>>> for UserFacingError
Allows you to create UserFacingErrors From std Errors wrapped in a Result
You should really just implement UFE for your error type, but if you wanted
to convert before quitting so you could add help text of something you can
use this.
impl<T: Debug> From<Result<T, Box<dyn Error>>> for UserFacingError
Allows you to create UserFacingErrors From std Errors wrapped in a Result You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.