Repository: rust-itertools/itertools
Pull request #719 (2023-07-28 04:54:24)

Allow to use EitherOrBoth<T> to mean the same as EitherOrBoth<T, T>

glandium: No, I was just trying to avoid the repeated type, which can be bothersome when it's long.

Patch:
diff --git a/src/either_or_both.rs b/src/either_or_both.rs
index d39747e..9dbc880 100644
--- a/src/either_or_both.rs
+++ b/src/either_or_both.rs
@@ -6,7 +6,7 @@ use either::Either;
 
 /// Value that either holds a single A or B, or both.
 #[derive(Clone, PartialEq, Eq, Hash, Debug)]
-pub enum EitherOrBoth<A, B> {
+pub enum EitherOrBoth<A, B = A> {
     /// Both values are present.
     Both(A, B),
     /// Only the left value of type `A` is present.


Test patch:
diff --git a/tests/merge_join.rs b/tests/merge_join.rs
index 870e1fa..776252f 100644
--- a/tests/merge_join.rs
+++ b/tests/merge_join.rs
@@ -5,7 +5,7 @@ use itertools::EitherOrBoth;
 fn empty() {
     let left: Vec<u32> = vec![];
     let right: Vec<u32> = vec![];
-    let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![];
+    let expected_result: Vec<EitherOrBoth<u32>> = vec![];
     let actual_result = merge_join_by(left, right, |l, r| l.cmp(r)).collect::<Vec<_>>();
     assert_eq!(expected_result, actual_result);
 }
@@ -14,7 +14,7 @@ fn empty() {
 fn left_only() {
     let left: Vec<u32> = vec![1, 2, 3];
     let right: Vec<u32> = vec![];
-    let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
+    let expected_result: Vec<EitherOrBoth<u32>> = vec![
         EitherOrBoth::Left(1),
         EitherOrBoth::Left(2),
         EitherOrBoth::Left(3),
@@ -27,7 +27,7 @@ fn left_only() {
 fn right_only() {
     let left: Vec<u32> = vec![];
     let right: Vec<u32> = vec![1, 2, 3];
-    let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
+    let expected_result: Vec<EitherOrBoth<u32>> = vec![
         EitherOrBoth::Right(1),
         EitherOrBoth::Right(2),
         EitherOrBoth::Right(3),
@@ -40,7 +40,7 @@ fn right_only() {
 fn first_left_then_right() {
     let left: Vec<u32> = vec![1, 2, 3];
     let right: Vec<u32> = vec![4, 5, 6];
-    let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
+    let expected_result: Vec<EitherOrBoth<u32>> = vec![
         EitherOrBoth::Left(1),
         EitherOrBoth::Left(2),
         EitherOrBoth::Left(3),
@@ -56,7 +56,7 @@ fn first_left_then_right() {
 fn first_right_then_left() {
     let left: Vec<u32> = vec![4, 5, 6];
     let right: Vec<u32> = vec![1, 2, 3];
-    let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
+    let expected_result: Vec<EitherOrBoth<u32>> = vec![
         EitherOrBoth::Right(1),
         EitherOrBoth::Right(2),
         EitherOrBoth::Right(3),
@@ -72,7 +72,7 @@ fn first_right_then_left() {
 fn interspersed_left_and_right() {
     let left: Vec<u32> = vec![1, 3, 5];
     let right: Vec<u32> = vec![2, 4, 6];
-    let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
+    let expected_result: Vec<EitherOrBoth<u32>> = vec![
         EitherOrBoth::Left(1),
         EitherOrBoth::Right(2),
         EitherOrBoth::Left(3),
@@ -88,7 +88,7 @@ fn interspersed_left_and_right() {
 fn overlapping_left_and_right() {
     let left: Vec<u32> = vec![1, 3, 4, 6];
     let right: Vec<u32> = vec![2, 3, 4, 5];
-    let expected_result: Vec<EitherOrBoth<u32, u32>> = vec![
+    let expected_result: Vec<EitherOrBoth<u32>> = vec![
         EitherOrBoth::Left(1),
         EitherOrBoth::Right(2),
         EitherOrBoth::Both(3, 3),