sqlx_rxqlite/types/
str.rs1use crate::decode::Decode;
3use crate::encode::{Encode, IsNull};
4use crate::error::BoxDynError;
5use crate::type_info::DataType;
6use crate::types::Type;
7use crate::{RXQLite, RXQLiteTypeInfo, RXQLiteValueRef};
8
9impl Type<RXQLite> for str {
10 fn type_info() -> RXQLiteTypeInfo {
11 RXQLiteTypeInfo(DataType::Text)
12 }
13}
14
15impl<'q> Encode<'q, RXQLite> for &'q str {
16 fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
17 args.push(rxqlite_common::Value::String(self.to_string()));
18
19 IsNull::No
20 }
21}
22impl Type<RXQLite> for Box<str> {
32 fn type_info() -> RXQLiteTypeInfo {
33 <&str as Type<RXQLite>>::type_info()
34 }
35}
36
37impl Encode<'_, RXQLite> for Box<str> {
38 fn encode(self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
39 args.push(rxqlite_common::Value::String(self.to_string()));
40
41 IsNull::No
42 }
43
44 fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
45 args.push(rxqlite_common::Value::String(self.to_string()));
46
47 IsNull::No
48 }
49}
50
51impl Decode<'_, RXQLite> for Box<str> {
52 fn decode(value: RXQLiteValueRef<'_>) -> Result<Self, BoxDynError> {
53 value.text().map(Box::from)
54 }
55}
56
57impl Type<RXQLite> for String {
58 fn type_info() -> RXQLiteTypeInfo {
59 <&str as Type<RXQLite>>::type_info()
60 }
61}
62
63impl<'q> Encode<'q, RXQLite> for String {
64 fn encode(self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
65 args.push(rxqlite_common::Value::String(self.to_string()));
66
67 IsNull::No
68 }
69
70 fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
71 args.push(rxqlite_common::Value::String(self.to_string()));
72
73 IsNull::No
74 }
75}
76
77impl<'r> Decode<'r, RXQLite> for String {
78 fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
79 value.text()
80 }
81}
82