Struct simple_error::SimpleError
source · pub struct SimpleError { /* private fields */ }
Expand description
A type that represents a simple error.
This type uses a String
to store the error string, and it implements std::error::Error
.
Implementations§
source§impl SimpleError
impl SimpleError
sourcepub fn new<T: Into<String>>(t: T) -> SimpleError
pub fn new<T: Into<String>>(t: T) -> SimpleError
Creates a new simple error.
This function can take any type that implements Into<String>
.
§Examples
use self::simple_error::SimpleError;
// errors can be created from `str`
let err = SimpleError::new("an error from str");
// errors can also be created from `String`
let err = SimpleError::new(String::from("an error from String"));
sourcepub fn from<T: Error>(t: T) -> SimpleError
pub fn from<T: Error>(t: T) -> SimpleError
Creates a new simple error from another error.
This function can take any type that implements std::error::Error
.
The error string will be the Display
of the std::error::Error
.
§Examples
use self::simple_error::SimpleError;
use std::io;
// errors can be created from `io::Error`
let err = SimpleError::from(io::Error::new(io::ErrorKind::Other, "oh no"));
assert_eq!("oh no", format!("{}", err));
sourcepub fn with<T: Error>(s: &str, t: T) -> SimpleError
pub fn with<T: Error>(s: &str, t: T) -> SimpleError
Creates a new simple error from a string with another error.
This function takes a string as error and a type that implements std::error::Error
as
reason.
The error string will be the Display
of the std::error::Error
prefixed with the string
and “, “.
§Examples
use self::simple_error::SimpleError;
let err = SimpleError::with("cannot turn on tv", SimpleError::new("remote not found"));
assert_eq!("cannot turn on tv, remote not found", format!("{}", err));
Trait Implementations§
source§impl Clone for SimpleError
impl Clone for SimpleError
source§fn clone(&self) -> SimpleError
fn clone(&self) -> SimpleError
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SimpleError
impl Debug for SimpleError
source§impl Display for SimpleError
impl Display for SimpleError
source§impl Error for SimpleError
impl Error for SimpleError
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
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()
source§impl<'a> From<&'a str> for SimpleError
impl<'a> From<&'a str> for SimpleError
source§fn from(s: &str) -> SimpleError
fn from(s: &str) -> SimpleError
Converts to this type from the input type.
source§impl Hash for SimpleError
impl Hash for SimpleError
source§impl Ord for SimpleError
impl Ord for SimpleError
source§fn cmp(&self, other: &SimpleError) -> Ordering
fn cmp(&self, other: &SimpleError) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for SimpleError
impl PartialEq for SimpleError
source§fn eq(&self, other: &SimpleError) -> bool
fn eq(&self, other: &SimpleError) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for SimpleError
impl PartialOrd for SimpleError
source§fn partial_cmp(&self, other: &SimpleError) -> Option<Ordering>
fn partial_cmp(&self, other: &SimpleError) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Eq for SimpleError
impl StructuralPartialEq for SimpleError
Auto Trait Implementations§
impl Freeze for SimpleError
impl RefUnwindSafe for SimpleError
impl Send for SimpleError
impl Sync for SimpleError
impl Unpin for SimpleError
impl UnwindSafe for SimpleError
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