diff --git a/src/lib.rs b/src/lib.rs index 3685349..250635e 100644 --- a/src/lib.rs +++ b/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 = 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(); + } } } diff --git a/src/types/to_sql.rs b/src/types/to_sql.rs index ed5da10..06b6ce1 100644 --- a/src/types/to_sql.rs +++ b/src/types/to_sql.rs @@ -84,6 +84,13 @@ pub trait ToSql { fn to_sql(&self) -> Result>; } +impl ToSql for Box { + fn to_sql(&self) -> Result> { + let derefed: &dyn ToSql = &**self; + derefed.to_sql() + } +} + // We should be able to use a generic impl like this: // // impl ToSql for T where T: Into {