Skip to content

Commit 919e347

Browse files
committed
Add impl ToSql for Cow<str> (see sfackler#280)
1 parent 1f11c47 commit 919e347

File tree

1 file changed

+13
-0
lines changed
  • postgres-shared/src/types

1 file changed

+13
-0
lines changed

postgres-shared/src/types/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use fallible_iterator::FallibleIterator;
44
use postgres_protocol;
55
use postgres_protocol::types::{self, ArrayDimension};
6+
use std::borrow::Cow;
67
use std::collections::HashMap;
78
use std::error::Error;
89
use std::fmt;
@@ -635,6 +636,18 @@ impl<'a> ToSql for &'a str {
635636
to_sql_checked!();
636637
}
637638

639+
impl<'a> ToSql for Cow<'a, str> {
640+
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
641+
<&str as ToSql>::to_sql(&&self.as_ref(), ty, w)
642+
}
643+
644+
fn accepts(ty: &Type) -> bool {
645+
<&str as ToSql>::accepts(ty)
646+
}
647+
648+
to_sql_checked!();
649+
}
650+
638651
impl ToSql for String {
639652
fn to_sql(&self, ty: &Type, w: &mut Vec<u8>) -> Result<IsNull, Box<Error + Sync + Send>> {
640653
<&str as ToSql>::to_sql(&&**self, ty, w)

0 commit comments

Comments
 (0)