Struct simple_error::SimpleError [] [src]

pub struct SimpleError {
    // some fields omitted
}

A type that represents a simple error.

This type uses a String to store the error string, and it implements std::error::Error.

Methods

impl SimpleError
[src]

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"));

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));

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

impl Eq for SimpleError
[src]

impl PartialEq for SimpleError
[src]

fn eq(&self, __arg_0: &SimpleError) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &SimpleError) -> bool

This method tests for !=.

impl Debug for SimpleError
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Clone for SimpleError
[src]

fn clone(&self) -> SimpleError

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl Display for SimpleError
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Error for SimpleError
[src]

fn description(&self) -> &str

A short description of the error. Read more

fn cause(&self) -> Option<&Error>
1.0.0

The lower-level cause of this error, if any. Read more