mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 19:41:37 +08:00
impl ToSql for Box<dyn ToSql>. Fixes #500
This commit is contained in:
parent
b24f3c5519
commit
d8074b1ece
12
src/lib.rs
12
src/lib.rs
@ -1615,5 +1615,17 @@ mod test {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_dyn_box() {
|
||||||
|
let db = checked_memory_handle();
|
||||||
|
db.execute_batch("CREATE TABLE foo(x INTEGER);").unwrap();
|
||||||
|
let b: Box<dyn ToSql> = Box::new(5);
|
||||||
|
db.execute("INSERT INTO foo VALUES(?)", &[b]).unwrap();
|
||||||
|
db.query_row("SELECT x FROM foo", params![], |r| {
|
||||||
|
assert_eq!(5, r.get_unwrap::<_, i32>(0));
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,13 @@ pub trait ToSql {
|
|||||||
fn to_sql(&self) -> Result<ToSqlOutput<'_>>;
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We should be able to use a generic impl like this:
|
// We should be able to use a generic impl like this:
|
||||||
//
|
//
|
||||||
// impl<T: Copy> ToSql for T where T: Into<Value> {
|
// impl<T: Copy> ToSql for T where T: Into<Value> {
|
||||||
|
Loading…
Reference in New Issue
Block a user