瀏覽代碼

Add Modelable impl for f64.

Kestrel 2 年之前
父節點
當前提交
de9317da73
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      microrm/src/model/modelable.rs

+ 12 - 0
microrm/src/model/modelable.rs

@@ -26,6 +26,18 @@ integral!(u32);
 integral!(i64);
 integral!(u64);
 
+impl Modelable for f64 {
+    fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
+        self.bind(stmt, col)
+    }
+    fn build_from(stmt: &sqlite::Statement, col_offset: usize) -> sqlite::Result<(Self, usize)>
+    where
+        Self: Sized,
+    {
+        stmt.read(col_offset).map(|x| (x, 1))
+    }
+}
+
 impl Modelable for bool {
     fn bind_to(&self, stmt: &mut sqlite::Statement, col: usize) -> sqlite::Result<()> {
         let val = if self == &true { 1i64 } else { 0i64 };