mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-21 03:36:06 +00:00
Add impl_from! macro to shorten up error code
This commit is contained in:
parent
9d3638fa46
commit
aae1d8b34f
6 changed files with 41 additions and 56 deletions
18
server/src/impl_from.rs
Normal file
18
server/src/impl_from.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/// Implements 'From' for a list of variants, intended for use with error enums
|
||||
/// that are wrapping a number of errors from other methods.
|
||||
#[macro_export]
|
||||
macro_rules! impl_from {
|
||||
(
|
||||
$enum_name: ident {
|
||||
$($error_type: ty => $variant_name: ident),* $(,)*
|
||||
}
|
||||
) => {
|
||||
$(
|
||||
impl From<$error_type> for $enum_name {
|
||||
fn from(error: $error_type) -> $enum_name {
|
||||
$enum_name::$variant_name(error)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue