diff --git a/either_of/src/lib.rs b/either_of/src/lib.rs index 5a5601e9cd..c41f2785e6 100644 --- a/either_of/src/lib.rs +++ b/either_of/src/lib.rs @@ -134,7 +134,7 @@ tuples!(EitherOf14 + EitherOf14Future + EitherOf14FutureProj => A, B, C, D, E, F tuples!(EitherOf15 + EitherOf15Future + EitherOf15FutureProj => A, B, C, D, E, F, G, H, I, J, K, L, M, N, O); tuples!(EitherOf16 + EitherOf16Future + EitherOf16FutureProj => A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P); -/// Matches over the first expression and returns an either ([`Either`], [`EitherOf3`], ... [`EitherOf6`]) +/// Matches over the first expression and returns an either ([`Either`], [`EitherOf3`], ... [`EitherOf8`]) /// composed of the values returned by the match arms. /// /// The pattern syntax is exactly the same as found in a match arm. @@ -197,6 +197,29 @@ macro_rules! either { $e_pattern => $crate::EitherOf6::E($e_expression), $f_pattern => $crate::EitherOf6::F($f_expression), } + }; + ($match:expr, $a_pattern:pat => $a_expression:expr, $b_pattern:pat => $b_expression:expr, $c_pattern:pat => $c_expression:expr, $d_pattern:pat => $d_expression:expr, $e_pattern:pat => $e_expression:expr, $f_pattern:pat => $f_expression:expr, $g_pattern:pat => $g_expression:expr,) => { + match $match { + $a_pattern => $crate::EitherOf7::A($a_expression), + $b_pattern => $crate::EitherOf7::B($b_expression), + $c_pattern => $crate::EitherOf7::C($c_expression), + $d_pattern => $crate::EitherOf7::D($d_expression), + $e_pattern => $crate::EitherOf7::E($e_expression), + $f_pattern => $crate::EitherOf7::F($f_expression), + $g_pattern => $crate::EitherOf7::G($g_expression), + } + }; + ($match:expr, $a_pattern:pat => $a_expression:expr, $b_pattern:pat => $b_expression:expr, $c_pattern:pat => $c_expression:expr, $d_pattern:pat => $d_expression:expr, $e_pattern:pat => $e_expression:expr, $f_pattern:pat => $f_expression:expr, $g_pattern:pat => $g_expression:expr, $h_pattern:pat => $h_expression:expr,) => { + match $match { + $a_pattern => $crate::EitherOf8::A($a_expression), + $b_pattern => $crate::EitherOf8::B($b_expression), + $c_pattern => $crate::EitherOf8::C($c_expression), + $d_pattern => $crate::EitherOf8::D($d_expression), + $e_pattern => $crate::EitherOf8::E($e_expression), + $f_pattern => $crate::EitherOf8::F($f_expression), + $g_pattern => $crate::EitherOf8::G($g_expression), + $h_pattern => $crate::EitherOf8::H($h_expression), + } }; // if you need more eithers feel free to open a PR ;-) } @@ -233,4 +256,23 @@ fn either_macro() { 16 => 24u8, _ => 12, ); + let _: EitherOf7<&str, f64, char, f32, u8, i8, i32> = either!(12, + 12 => "12", + 13 => 0.0, + 14 => ' ', + 15 => 0.0f32, + 16 => 24u8, + 17 => 2i8, + _ => 12, + ); + let _: EitherOf8<&str, f64, char, f32, u8, i8, u32, i32> = either!(12, + 12 => "12", + 13 => 0.0, + 14 => ' ', + 15 => 0.0f32, + 16 => 24u8, + 17 => 2i8, + 18 => 42u32, + _ => 12, + ); }