macro_rules! define_error {
(
$(#[$docs:meta])*
$vis:vis $enum_name:ident<$args_type:ty> {
$($name:ident($code:expr, $msg:expr);)+
}
) => { ... };
}Expand description
定义错误类型,携带 code、msg 和一个自定义类型的数据
§Example
aux_svc::define_error! {
// 可用于传递 i18n 参数
pub AppError<aux_i18n::Args<'static>> {
MissBody(1, "miss_body");
InvalidParams(2, "invalid_params");
}
}
println!(AppError::MissBody(None)); // 无 i18n 参数
println!(AppError::InvalidParams(Some(fluent::fluent_args![ // 传递 i18n 参数
"field" => "name",
])))