sqlx_rxqlite/types/
uint.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, /*RXQLiteArgumentValue,*/ RXQLiteTypeInfo, RXQLiteValueRef};
7
8impl Type<RXQLite> for u8 {
9    fn type_info() -> RXQLiteTypeInfo {
10        RXQLiteTypeInfo(DataType::Int)
11    }
12
13    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
14        matches!(ty.0, DataType::Int | DataType::Int64)
15    }
16}
17
18impl<'q> Encode<'q, RXQLite> for u8 {
19    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
20        args.push(rxqlite_common::Value::Int((*self).into()));
21
22        IsNull::No
23    }
24}
25
26impl<'r> Decode<'r, RXQLite> for u8 {
27    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
28        Ok(value.int()? as _)
29    }
30}
31
32impl Type<RXQLite> for u16 {
33    fn type_info() -> RXQLiteTypeInfo {
34        RXQLiteTypeInfo(DataType::Int)
35    }
36
37    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
38        matches!(ty.0, DataType::Int | DataType::Int64)
39    }
40}
41
42impl<'q> Encode<'q, RXQLite> for u16 {
43    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
44        args.push(rxqlite_common::Value::Int((*self).into()));
45
46        IsNull::No
47    }
48}
49
50impl<'r> Decode<'r, RXQLite> for u16 {
51    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
52        Ok(value.int()? as _)
53    }
54}
55
56impl Type<RXQLite> for u32 {
57    fn type_info() -> RXQLiteTypeInfo {
58        RXQLiteTypeInfo(DataType::Int64)
59    }
60
61    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
62        matches!(ty.0, DataType::Int | DataType::Int64)
63    }
64}
65
66impl<'q> Encode<'q, RXQLite> for u32 {
67    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
68        args.push(rxqlite_common::Value::Int((*self).into()));
69
70        IsNull::No
71    }
72}
73
74impl<'r> Decode<'r, RXQLite> for u32 {
75    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
76        Ok(value.int64()? as _)
77    }
78}