Macro implement_string_error_in_enum

Source
macro_rules! implement_string_error_in_enum {
    ($enum_error:ident, $err_type: path, $enum_variant: path) => { ... };
}
Expand description

Generate the From trait implementation for an custom enum error using ToString trait.

§Params

    implement_error_in_enum!($enum_error, $err_type, $enum_variant);

§Example

use std::fmt::Debug;
use heimdall_errors::implement_string_error_in_enum;


pub (crate) enum EnumError {
    IO(String)
}


// Implement From<Error> for StructError.
implement_string_error_in_enum!(EnumError, std::io::Error, EnumError::IO);

§Code generated

The code

implement_string_error_in_enum!(EnumError, std::io::Error, EnumError::IO);

generates the next code

 impl From<std::io::Error> for EnumError {
    fn from(err: std::io::Error) -> Self {
        EnumError::Io(err.to_string())
     }
 }