From aa64e2fb33755c696337d443ac4e8af93551ad05 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Tue, 5 Dec 2017 19:40:09 -0500 Subject: [PATCH] Remove potentially conflicting impl of ToSqlOutput. Replace with manual implementations of all the types we provided impls for before. --- src/types/to_sql.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/types/to_sql.rs b/src/types/to_sql.rs index 53e4f38..ba8f5da 100644 --- a/src/types/to_sql.rs +++ b/src/types/to_sql.rs @@ -15,6 +15,8 @@ pub enum ToSqlOutput<'a> { ZeroBlob(i32), } +// Generically allow any type that can be converted into a ValueRef +// to be converted into a ToSqlOutput as well. impl<'a, T: ?Sized> From<&'a T> for ToSqlOutput<'a> where &'a T: Into> { @@ -23,11 +25,31 @@ impl<'a, T: ?Sized> From<&'a T> for ToSqlOutput<'a> } } -impl<'a, T: Into> From for ToSqlOutput<'a> { - fn from(t: T) -> Self { - ToSqlOutput::Owned(t.into()) - } -} +// We cannot also generically allow any type that can be converted +// into a Value to be converted into a ToSqlOutput because of +// coherence rules (https://github.com/rust-lang/rust/pull/46192), +// so we'll manually implement it for all the types we know can +// be converted into Values. +macro_rules! from_value( + ($t:ty) => ( + impl<'a> From<$t> for ToSqlOutput<'a> { + fn from(t: $t) -> Self { ToSqlOutput::Owned(t.into())} + } + ) +); +from_value!(String); +from_value!(Null); +from_value!(bool); +from_value!(i8); +from_value!(i16); +from_value!(i32); +from_value!(i64); +from_value!(isize); +from_value!(u8); +from_value!(u16); +from_value!(u32); +from_value!(f64); +from_value!(Vec); impl<'a> ToSql for ToSqlOutput<'a> { fn to_sql(&self) -> Result {