mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 22:08:55 +08:00 
			
		
		
		
	Cow<str> now implements ToSql.
This commit is contained in:
		| @@ -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()); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user