pub struct Error { /* private fields */ }Expand description
An error in a command-line operation.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new<E: Into<Box<dyn Error + Sync + Send>>>(
kind: ErrorKind,
error: E,
) -> Self
pub fn new<E: Into<Box<dyn Error + Sync + Send>>>( kind: ErrorKind, error: E, ) -> Self
Constructs a new Error with the specified ErrorKind and extended error information.
§Example
use clapi::{Error, ErrorKind};
let error = Error::new(ErrorKind::InvalidArgumentCount, "expect 1 or more arguments");
assert!(matches!(error.kind(), ErrorKind::InvalidArgumentCount));Sourcepub fn with_message<S: Into<Box<dyn Error + Sync + Send>>>(
&self,
msg: S,
) -> Self
pub fn with_message<S: Into<Box<dyn Error + Sync + Send>>>( &self, msg: S, ) -> Self
Returns this error with the given message.
§Example
use clapi::{Error, ErrorKind};
let error = Error::from(ErrorKind::InvalidArgument("xyz".to_string()));
let new_error = error.with_message("expected a number");
assert_eq!(new_error.to_string(), "invalid value for argument 'xyz': expected a number".to_string())Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more