generalize impl_froms to nested enums

This commit is contained in:
Aleksey Kladov
2019-09-13 00:31:04 +03:00
parent 45117c6388
commit bcf30d389c
4 changed files with 26 additions and 58 deletions

View File

@@ -8,13 +8,20 @@
//! applied. So, the relation between syntax and HIR is many-to-one.
macro_rules! impl_froms {
($e:ident: $($v:ident),*) => {
($e:ident: $($v:ident $(($($sv:ident),*))?),*) => {
$(
impl From<$v> for $e {
fn from(it: $v) -> $e {
$e::$v(it)
}
}
$($(
impl From<$sv> for $e {
fn from(it: $sv) -> $e {
$e::$v($v::$sv(it))
}
}
)*)?
)*
}
}