From d8074b1eceef28215e13030d6ba25f71aaa3984f Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Wed, 27 Mar 2019 16:46:54 -0700 Subject: [PATCH] impl ToSql for Box. Fixes #500 --- src/lib.rs | 12 ++++++++++++ src/types/to_sql.rs | 7 +++++++ 2 files changed, 19 insertions(+) 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 {