mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-22 16:29:20 +08:00
Merge pull request #501 from thomcc/box-dyn-tosql
impl ToSql for Box<dyn ToSql>. Fixes #500
This commit is contained in:
commit
22614c64bd
12
src/lib.rs
12
src/lib.rs
@ -1615,5 +1615,17 @@ mod test {
|
||||
})
|
||||
.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<'_>>;
|
||||
}
|
||||
|
||||
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:
|
||||
//
|
||||
// impl<T: Copy> ToSql for T where T: Into<Value> {
|
||||
|
Loading…
Reference in New Issue
Block a user