macro_rules! implement_error {
($struct_error:ident, $error_type: path, $error_kind: path) => { ... };
}Expand description
Implement the From trait for an struct with kind structure
§Params
ⓘ
implement_in_error_in_struct($struct_error, $error_type, $error_kind);§Example
use heimdall_errors::implement_error;
use std::env::VarError;
pub enum ErrorKind {
Var,
}
pub struct StructError {
kind: ErrorKind,
message: String,
}
// Implement From<VarError> for StructError.
implement_error!(StructError, VarError, ErrorKind::Var);
§Code generated
The code
ⓘ
implement_error!(StructError, VarError, ErrorKind::Var);generates the next code
ⓘ
impl From<VarError> for StructError {
fn from(err: VarError) -> Self {
Self {
kind: ErrorKind::Var,
message: err.to_string(),
}
}
}