From 919e347fbc13b0ff8579093063c1d4de836e76b8 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 3 Aug 2017 09:21:15 +0200 Subject: [PATCH] Add impl ToSql for Cow (see #280) --- postgres-shared/src/types/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/postgres-shared/src/types/mod.rs b/postgres-shared/src/types/mod.rs index 4937cc32..6917dd1c 100644 --- a/postgres-shared/src/types/mod.rs +++ b/postgres-shared/src/types/mod.rs @@ -3,6 +3,7 @@ use fallible_iterator::FallibleIterator; use postgres_protocol; use postgres_protocol::types::{self, ArrayDimension}; +use std::borrow::Cow; use std::collections::HashMap; use std::error::Error; use std::fmt; @@ -635,6 +636,18 @@ impl<'a> ToSql for &'a str { to_sql_checked!(); } +impl<'a> ToSql for Cow<'a, str> { + fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { + <&str as ToSql>::to_sql(&&self.as_ref(), ty, w) + } + + fn accepts(ty: &Type) -> bool { + <&str as ToSql>::accepts(ty) + } + + to_sql_checked!(); +} + impl ToSql for String { fn to_sql(&self, ty: &Type, w: &mut Vec) -> Result> { <&str as ToSql>::to_sql(&&**self, ty, w)