Hack around rust-lang/rust#24308

Closes #111
This commit is contained in:
Steven Fackler 2015-04-12 11:10:02 -07:00
parent b7313cef71
commit 2bf9b09af9
2 changed files with 21 additions and 3 deletions

View File

@ -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<IsNull> {
if !<&'a [u8] as ToSql>::accepts(ty) {
return Err(Error::WrongType(ty.clone()));
}
self.to_sql(ty, out)
}
fn to_sql<W: Write+?Sized>(&self, _: &Type, w: &mut W) -> Result<IsNull> {
try!(w.write_all(*self));
@ -691,7 +697,13 @@ impl ToSql for Vec<u8> {
}
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<IsNull> {
if !<&'a str as ToSql>::accepts(ty) {
return Err(Error::WrongType(ty.clone()));
}
self.to_sql(ty, out)
}
fn to_sql<W: Write+?Sized>(&self, _: &Type, w: &mut W) -> Result<IsNull> {
try!(w.write_all(self.as_bytes()));

View File

@ -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<IsNull> {
if !<Slice<'a, T> as ToSql>::accepts(ty) {
return Err(Error::WrongType(ty.clone()));
}
self.to_sql(ty, out)
}
fn to_sql<W: Write+?Sized>(&self, ty: &Type, mut w: &mut W) -> Result<IsNull> {
let member_type = match ty.kind() {