Macro nes::impl_from_error [] [src]

macro_rules! impl_from_error {
    ( $from_error:ident => $to_error:ident ) => { ... };
    ( $from_error:path => $to_error:ident :: $to_variant:ident ) => { ... };
}

This macro implements From trait for other errors.

It allows you to convert other errors into current and write something like function(..)?. Note, that you must use this macro only for errors, that have been defined with define_error!(). For errors like std::io::Error you must use try!() macro, because it gets information, where this error has been occurred.

# Example

impl_from_error!(ReadFileError => CommonError);

fn read_file(file_name:String) -> result![Vec<String>,ReadFileError] { ... }

fn process() -> result![CommonError] { //Or Result<CommonError>
    let lines=read_file(file_name)?;
    ...
}

You will get error like:

example/examples/example.rs 16:0   //line, where impl_from_error!() is.
read file error example/examples/example.rs 51:13    //line where the error has been occurred
Can not read file "no_file.rs" : No such file or directory (os error 2)    //description of error

Where is second form

# Example

impl_from_error!(::module::ReadFileError => CommonError::CanNotReadFile);