From 911b776e46dca39ffb1cdab2b845afe233d17f53 Mon Sep 17 00:00:00 2001 From: bicarlsen Date: Sun, 8 Dec 2024 00:00:40 +0100 Subject: [PATCH 1/4] INcrease number of branch arms for `either!` macro Increased number of possible branch arms for the `either!` macro from 6 to 8. --- either_of/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/either_of/src/lib.rs b/either_of/src/lib.rs index 5a5601e9cd..b68c795af7 100644 --- a/either_of/src/lib.rs +++ b/either_of/src/lib.rs @@ -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 ;-) } From e50aec5f652f8a1fa46eb6797bb4017e8e40d348 Mon Sep 17 00:00:00 2001 From: bicarlsen Date: Sun, 8 Dec 2024 00:08:05 +0100 Subject: [PATCH 2/4] Added tests for increased `either!` macro branches --- either_of/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/either_of/src/lib.rs b/either_of/src/lib.rs index b68c795af7..79b97033e5 100644 --- a/either_of/src/lib.rs +++ b/either_of/src/lib.rs @@ -256,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 _: EitherOf7<&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, + ); } From 1e113960ce7c3757972365890965c89c582719f8 Mon Sep 17 00:00:00 2001 From: bicarlsen Date: Sun, 8 Dec 2024 00:11:29 +0100 Subject: [PATCH 3/4] Update docs of `either!` macro for increased branches. --- either_of/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/either_of/src/lib.rs b/either_of/src/lib.rs index 79b97033e5..2184fc3caa 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. From 232565ed7e5e0949ef0a4e14e1bf8d0fe88eb528 Mon Sep 17 00:00:00 2001 From: bicarlsen Date: Sun, 8 Dec 2024 01:03:47 +0100 Subject: [PATCH 4/4] Fixed bug in `either!` macro test --- either_of/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/either_of/src/lib.rs b/either_of/src/lib.rs index 2184fc3caa..c41f2785e6 100644 --- a/either_of/src/lib.rs +++ b/either_of/src/lib.rs @@ -265,7 +265,7 @@ fn either_macro() { 17 => 2i8, _ => 12, ); - let _: EitherOf7<&str, f64, char, f32, u8, i8, u32, i32> = either!(12, + let _: EitherOf8<&str, f64, char, f32, u8, i8, u32, i32> = either!(12, 12 => "12", 13 => 0.0, 14 => ' ',