Cow<str> now implements ToSql.

This commit is contained in:
gwenn 2018-07-28 08:01:24 +02:00
parent a7479488b8
commit 5351d88bc0

View File

@ -1,3 +1,4 @@
use std::borrow::Cow;
use super::{Null, Value, ValueRef}; use super::{Null, Value, ValueRef};
use Result; use Result;
@ -149,6 +150,12 @@ impl<T: ToSql> ToSql for Option<T> {
} }
} }
impl<'a> ToSql for Cow<'a, str> {
fn to_sql(&self) -> Result<ToSqlOutput> {
Ok(ToSqlOutput::from(self.as_ref()))
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::ToSql; use super::ToSql;
@ -165,4 +172,16 @@ mod test {
is_to_sql::<u16>(); is_to_sql::<u16>();
is_to_sql::<u32>(); is_to_sql::<u32>();
} }
#[test]
fn test_cow_str() {
use std::borrow::Cow;
let s = "str";
let cow = Cow::Borrowed(s);
let r = cow.to_sql();
assert!(r.is_ok());
let cow = Cow::Owned::<str>(String::from(s));
let r = cow.to_sql();
assert!(r.is_ok());
}
} }