mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 16:29:20 +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:
parent
761df93a83
commit
2a04f06a3a
@ -87,37 +87,27 @@ pub trait ToSql {
|
||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>>;
|
||||
}
|
||||
|
||||
impl ToSql for Box<dyn ToSql> {
|
||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
||||
let derefed: &dyn ToSql = &**self;
|
||||
derefed.to_sql()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ToSql + Clone> ToSql for Cow<'_, T> {
|
||||
impl<T: ToSql + Clone + ?Sized> ToSql for Cow<'_, T> {
|
||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
|
||||
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<'_>> {
|
||||
let derefed: &dyn ToSql = &**self;
|
||||
derefed.to_sql()
|
||||
self.as_ref().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<'_>> {
|
||||
let derefed: &dyn ToSql = &**self;
|
||||
derefed.to_sql()
|
||||
self.as_ref().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<'_>> {
|
||||
let derefed: &dyn ToSql = &**self;
|
||||
derefed.to_sql()
|
||||
self.as_ref().to_sql()
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,13 +229,29 @@ mod 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 r = s.to_sql();
|
||||
|
||||
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]
|
||||
fn test_cells() {
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
Loading…
Reference in New Issue
Block a user