rbdc_sqlite/types/
uint.rs

1use crate::decode::Decode;
2use crate::encode::{Encode, IsNull};
3use crate::type_info::DataType;
4use crate::types::Type;
5use crate::{SqliteArgumentValue, SqliteTypeInfo, SqliteValue};
6use rbdc::error::Error;
7
8impl Type for u8 {
9    fn type_info(&self) -> SqliteTypeInfo {
10        SqliteTypeInfo(DataType::Int)
11    }
12}
13
14impl Encode for u8 {
15    fn encode(self, args: &mut Vec<SqliteArgumentValue>) -> Result<IsNull, Error> {
16        args.push(SqliteArgumentValue::Int(self as i32));
17
18        Ok(IsNull::No)
19    }
20}
21
22impl Decode for u8 {
23    fn decode(value: SqliteValue) -> Result<Self, Error> {
24        Ok(value.int().try_into()?)
25    }
26}
27
28impl Type for u16 {
29    fn type_info(&self) -> SqliteTypeInfo {
30        SqliteTypeInfo(DataType::Int)
31    }
32}
33
34impl Encode for u16 {
35    fn encode(self, args: &mut Vec<SqliteArgumentValue>) -> Result<IsNull, Error> {
36        args.push(SqliteArgumentValue::Int(self as i32));
37
38        Ok(IsNull::No)
39    }
40}
41
42impl Decode for u16 {
43    fn decode(value: SqliteValue) -> Result<Self, Error> {
44        Ok(value.int().try_into()?)
45    }
46}
47
48impl Type for u32 {
49    fn type_info(&self) -> SqliteTypeInfo {
50        SqliteTypeInfo(DataType::Int64)
51    }
52}
53
54impl Encode for u32 {
55    fn encode(self, args: &mut Vec<SqliteArgumentValue>) -> Result<IsNull, Error> {
56        args.push(SqliteArgumentValue::Int64(self as i64));
57
58        Ok(IsNull::No)
59    }
60}
61
62impl Decode for u32 {
63    fn decode(value: SqliteValue) -> Result<Self, Error> {
64        Ok(value.int64().try_into()?)
65    }
66}