From 56dd19ef75557dffa250ec4135ee08eb556e88f4 Mon Sep 17 00:00:00 2001 From: Muhannad Alrusayni Date: Fri, 17 Sep 2021 21:59:38 +0300 Subject: [PATCH 1/3] Impl TryGetableMany for diffrent types of generices --- src/executor/query.rs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index ba8c81698..5bb1661bb 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -314,29 +314,50 @@ where } } -impl TryGetableMany for (T, T) +impl TryGetableMany for (A, B) where - T: TryGetable, + A: TryGetable, + B: TryGetable, { fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result { try_get_many_with_slice_len_of(2, cols)?; Ok(( - T::try_get(res, pre, &cols[0])?, - T::try_get(res, pre, &cols[1])?, + A::try_get(res, pre, &cols[0])?, + B::try_get(res, pre, &cols[1])?, )) } } -impl TryGetableMany for (T, T, T) +impl TryGetableMany for (A, B, C) where - T: TryGetable, + A: TryGetable, + B: TryGetable, + C: TryGetable, { fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result { try_get_many_with_slice_len_of(3, cols)?; Ok(( - T::try_get(res, pre, &cols[0])?, - T::try_get(res, pre, &cols[1])?, - T::try_get(res, pre, &cols[2])?, + A::try_get(res, pre, &cols[0])?, + B::try_get(res, pre, &cols[1])?, + C::try_get(res, pre, &cols[2])?, + )) + } +} + +impl TryGetableMany for (A, B, C, D) +where + A: TryGetable, + B: TryGetable, + C: TryGetable, + D: TryGetable, +{ + fn try_get_many(res: &QueryResult, pre: &str, cols: &[String]) -> Result { + try_get_many_with_slice_len_of(4, cols)?; + Ok(( + A::try_get(res, pre, &cols[0])?, + B::try_get(res, pre, &cols[1])?, + C::try_get(res, pre, &cols[2])?, + D::try_get(res, pre, &cols[3])?, )) } } From 3bf26a758a0ed6464ff48c08e2363155e1c82072 Mon Sep 17 00:00:00 2001 From: Muhannad Alrusayni Date: Fri, 17 Sep 2021 22:41:49 +0300 Subject: [PATCH 2/3] impl `TryFromU64` for tuples types --- src/executor/query.rs | 73 +++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index 5bb1661bb..ec8178a7b 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -391,15 +391,27 @@ macro_rules! try_from_u64_err { } } }; -} -macro_rules! try_from_u64_tuple { - ( $type: ty ) => { - try_from_u64_err!(($type, $type)); - try_from_u64_err!(($type, $type, $type)); + ( $($gen_type: ident),* ) => { + impl<$( $gen_type, )*> TryFromU64 for ($( $gen_type, )*) + where + $( $gen_type: TryFromU64, )* + { + fn try_from_u64(_: u64) -> Result { + Err(DbErr::Exec(format!( + "{} cannot be converted from u64", + stringify!(($($gen_type,)*)) + ))) + } + } }; } +// impl TryFromU64 for tuples with generic types +try_from_u64_err!(A, B); +try_from_u64_err!(A, B, C); +try_from_u64_err!(A, B, C, D); + macro_rules! try_from_u64_numeric { ( $type: ty ) => { impl TryFromU64 for $type { @@ -414,7 +426,6 @@ macro_rules! try_from_u64_numeric { }) } } - try_from_u64_tuple!($type); }; } @@ -434,19 +445,49 @@ macro_rules! try_from_u64_string { Ok(n.to_string()) } } - try_from_u64_tuple!($type); }; } try_from_u64_string!(String); -macro_rules! try_from_u64_dummy { - ( $type: ty ) => { - try_from_u64_err!($type); - try_from_u64_err!(($type, $type)); - try_from_u64_err!(($type, $type, $type)); - }; -} - #[cfg(feature = "with-uuid")] -try_from_u64_dummy!(uuid::Uuid); +try_from_u64_err!(uuid::Uuid); + +// impl TryFromU64 for (A, B) +// where +// A: TryFromU64, +// B: TryFromU64, +// { +// fn try_from_u64(_: u64) -> Result { +// Err(DbErr::Exec( +// "(A, B) cannot be converted from u64".to_owned(), +// )) +// } +// } + +// impl TryFromU64 for (A, B, C) +// where +// A: TryFromU64, +// B: TryFromU64, +// C: TryFromU64, +// { +// fn try_from_u64(_: u64) -> Result { +// Err(DbErr::Exec( +// "(A, B, C) cannot be converted from u64".to_owned(), +// )) +// } +// } + +// impl TryFromU64 for (A, B, C, D) +// where +// A: TryFromU64, +// B: TryFromU64, +// C: TryFromU64, +// D: TryFromU64, +// { +// fn try_from_u64(_: u64) -> Result { +// Err(DbErr::Exec( +// "(A, B, C, D) cannot be converted from u64".to_owned(), +// )) +// } +// } From 15db5d293325ddf738a1d00b13b3c274863c25d9 Mon Sep 17 00:00:00 2001 From: Muhannad Alrusayni Date: Fri, 17 Sep 2021 22:45:05 +0300 Subject: [PATCH 3/3] clean up some comments --- src/executor/query.rs | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index ec8178a7b..ae09f97c7 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -452,42 +452,3 @@ try_from_u64_string!(String); #[cfg(feature = "with-uuid")] try_from_u64_err!(uuid::Uuid); - -// impl TryFromU64 for (A, B) -// where -// A: TryFromU64, -// B: TryFromU64, -// { -// fn try_from_u64(_: u64) -> Result { -// Err(DbErr::Exec( -// "(A, B) cannot be converted from u64".to_owned(), -// )) -// } -// } - -// impl TryFromU64 for (A, B, C) -// where -// A: TryFromU64, -// B: TryFromU64, -// C: TryFromU64, -// { -// fn try_from_u64(_: u64) -> Result { -// Err(DbErr::Exec( -// "(A, B, C) cannot be converted from u64".to_owned(), -// )) -// } -// } - -// impl TryFromU64 for (A, B, C, D) -// where -// A: TryFromU64, -// B: TryFromU64, -// C: TryFromU64, -// D: TryFromU64, -// { -// fn try_from_u64(_: u64) -> Result { -// Err(DbErr::Exec( -// "(A, B, C, D) cannot be converted from u64".to_owned(), -// )) -// } -// }