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