Merge pull request #368 from gwenn/cow

Cow<str> now implements ToSql.
This commit is contained in:
gwenn
2018-07-28 12:18:44 +02:00
committed by GitHub

View File

@@ -1,3 +1,4 @@
use std::borrow::Cow;
use super::{Null, Value, ValueRef};
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)]
mod test {
use super::ToSql;
@@ -165,4 +172,16 @@ mod test {
is_to_sql::<u16>();
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());
}
}