1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::rqlite;
use crate::decode::Decode;
use crate::encode::{Encode, IsNull};
use crate::error::BoxDynError;
use crate::type_info::DataType;
use crate::types::Type;
use crate::{Rqlite, /*SqliteArgumentValue,*/ RqliteTypeInfo, RqliteValueRef};

impl Type<Rqlite> for f32 {
    fn type_info() -> RqliteTypeInfo {
        RqliteTypeInfo(DataType::Float)
    }
}

impl<'q> Encode<'q, Rqlite> for f32 {
    fn encode_by_ref(&self, args: &mut Vec<rqlite::Value>) -> IsNull {
        args.push(rqlite::Value::from(*self));

        IsNull::No
    }
}

impl<'r> Decode<'r, Rqlite> for f32 {
    fn decode(value: RqliteValueRef<'r>) -> Result<f32, BoxDynError> {
        Ok(value.double()? as f32)
    }
}

impl Type<Rqlite> for f64 {
    fn type_info() -> RqliteTypeInfo {
        RqliteTypeInfo(DataType::Float)
    }
}

impl<'q> Encode<'q, Rqlite> for f64 {
    fn encode_by_ref(&self, args: &mut Vec<rqlite::Value>) -> IsNull {
        args.push(rqlite::Value::from(*self));

        IsNull::No
    }
}

impl<'r> Decode<'r, Rqlite> for f64 {
    fn decode(value: RqliteValueRef<'r>) -> Result<f64, BoxDynError> {
        Ok(value.double()?)
    }
}