mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-10-31 13:58:55 +08:00 
			
		
		
		
	Relaxed Sized bound on Box/Rc/Arc/Cow for ToSql
* Fix Box<T> for unsized * refactoring * Add more tests * ?Sized for Cow, Rc, Arc too
This commit is contained in:
		| @@ -87,37 +87,27 @@ pub trait ToSql { | |||||||
|     fn to_sql(&self) -> Result<ToSqlOutput<'_>>; |     fn to_sql(&self) -> Result<ToSqlOutput<'_>>; | ||||||
| } | } | ||||||
|  |  | ||||||
| impl ToSql for Box<dyn ToSql> { | impl<T: ToSql + Clone + ?Sized> ToSql for Cow<'_, T> { | ||||||
|     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { |  | ||||||
|         let derefed: &dyn ToSql = &**self; |  | ||||||
|         derefed.to_sql() |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| impl<T: ToSql + Clone> ToSql for Cow<'_, T> { |  | ||||||
|     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { |     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { | ||||||
|         self.as_ref().to_sql() |         self.as_ref().to_sql() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<T: ToSql> ToSql for Box<T> { | impl<T: ToSql + ?Sized> ToSql for Box<T> { | ||||||
|     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { |     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { | ||||||
|         let derefed: &dyn ToSql = &**self; |         self.as_ref().to_sql() | ||||||
|         derefed.to_sql() |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<T: ToSql> ToSql for std::rc::Rc<T> { | impl<T: ToSql + ?Sized> ToSql for std::rc::Rc<T> { | ||||||
|     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { |     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { | ||||||
|         let derefed: &dyn ToSql = &**self; |         self.as_ref().to_sql() | ||||||
|         derefed.to_sql() |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<T: ToSql> ToSql for std::sync::Arc<T> { | impl<T: ToSql + ?Sized> ToSql for std::sync::Arc<T> { | ||||||
|     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { |     fn to_sql(&self) -> Result<ToSqlOutput<'_>> { | ||||||
|         let derefed: &dyn ToSql = &**self; |         self.as_ref().to_sql() | ||||||
|         derefed.to_sql() |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -239,13 +229,29 @@ mod test { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_box() { |     fn test_box_dyn() { | ||||||
|  |         let s: Box<dyn ToSql> = Box::new("Hello world!"); | ||||||
|  |         let r = ToSql::to_sql(&s); | ||||||
|  |  | ||||||
|  |         assert!(r.is_ok()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[test] | ||||||
|  |     fn test_box_deref() { | ||||||
|         let s: Box<str> = "Hello world!".into(); |         let s: Box<str> = "Hello world!".into(); | ||||||
|         let r = s.to_sql(); |         let r = s.to_sql(); | ||||||
|  |  | ||||||
|         assert!(r.is_ok()); |         assert!(r.is_ok()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     #[test] | ||||||
|  |     fn test_box_direct() { | ||||||
|  |         let s: Box<str> = "Hello world!".into(); | ||||||
|  |         let r = ToSql::to_sql(&s); | ||||||
|  |  | ||||||
|  |         assert!(r.is_ok()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_cells() { |     fn test_cells() { | ||||||
|         use std::{rc::Rc, sync::Arc}; |         use std::{rc::Rc, sync::Arc}; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user