From 2bf9b09af9d7476fc5472544cf9d13b050af7014 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 12 Apr 2015 11:10:02 -0700 Subject: [PATCH] Hack around rust-lang/rust#24308 Closes #111 --- src/types/mod.rs | 16 ++++++++++++++-- src/types/slice.rs | 8 +++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/types/mod.rs b/src/types/mod.rs index cb7b52f2..43578b45 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -668,7 +668,13 @@ impl ToSql for bool { } impl<'a> ToSql for &'a [u8] { - to_sql_checked!(); + // FIXME should use to_sql_checked!() but blocked on rust-lang/rust#24308 + fn to_sql_checked(&self, ty: &Type, out: &mut Write) -> Result { + if !<&'a [u8] as ToSql>::accepts(ty) { + return Err(Error::WrongType(ty.clone())); + } + self.to_sql(ty, out) + } fn to_sql(&self, _: &Type, w: &mut W) -> Result { try!(w.write_all(*self)); @@ -691,7 +697,13 @@ impl ToSql for Vec { } impl<'a> ToSql for &'a str { - to_sql_checked!(); + // FIXME should use to_sql_checked!() but blocked on rust-lang/rust#24308 + fn to_sql_checked(&self, ty: &Type, out: &mut Write) -> Result { + if !<&'a str as ToSql>::accepts(ty) { + return Err(Error::WrongType(ty.clone())); + } + self.to_sql(ty, out) + } fn to_sql(&self, _: &Type, w: &mut W) -> Result { try!(w.write_all(self.as_bytes())); diff --git a/src/types/slice.rs b/src/types/slice.rs index dc70aeeb..3f795830 100644 --- a/src/types/slice.rs +++ b/src/types/slice.rs @@ -28,7 +28,13 @@ use types::IsNull; pub struct Slice<'a, T: 'a + ToSql>(pub &'a [T]); impl<'a, T: 'a + ToSql> ToSql for Slice<'a, T> { - to_sql_checked!(); + // FIXME should use to_sql_checked!() but blocked on rust-lang/rust#24308 + fn to_sql_checked(&self, ty: &Type, out: &mut Write) -> Result { + if ! as ToSql>::accepts(ty) { + return Err(Error::WrongType(ty.clone())); + } + self.to_sql(ty, out) + } fn to_sql(&self, ty: &Type, mut w: &mut W) -> Result { let member_type = match ty.kind() {