sqlx_rxqlite/types/
float.rs

1use crate::decode::Decode;
2use crate::encode::{Encode, IsNull};
3use crate::error::BoxDynError;
4use crate::type_info::DataType;
5use crate::types::Type;
6use crate::{RXQLite, /*SqliteArgumentValue,*/ RXQLiteTypeInfo, RXQLiteValueRef};
7
8impl Type<RXQLite> for f32 {
9    fn type_info() -> RXQLiteTypeInfo {
10        RXQLiteTypeInfo(DataType::Float)
11    }
12}
13
14impl<'q> Encode<'q, RXQLite> for f32 {
15    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
16        args.push(rxqlite_common::Value::from(*self));
17
18        IsNull::No
19    }
20}
21
22impl<'r> Decode<'r, RXQLite> for f32 {
23    fn decode(value: RXQLiteValueRef<'r>) -> Result<f32, BoxDynError> {
24        Ok(value.double()? as f32)
25    }
26}
27
28impl Type<RXQLite> for f64 {
29    fn type_info() -> RXQLiteTypeInfo {
30        RXQLiteTypeInfo(DataType::Float)
31    }
32}
33
34impl<'q> Encode<'q, RXQLite> for f64 {
35    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
36        args.push(rxqlite_common::Value::from(*self));
37
38        IsNull::No
39    }
40}
41
42impl<'r> Decode<'r, RXQLite> for f64 {
43    fn decode(value: RXQLiteValueRef<'r>) -> Result<f64, BoxDynError> {
44        Ok(value.double()?)
45    }
46}