sqlx_rxqlite/types/
str.rs

1//use std::borrow::Cow;
2use crate::decode::Decode;
3use crate::encode::{Encode, IsNull};
4use crate::error::BoxDynError;
5use crate::type_info::DataType;
6use crate::types::Type;
7use crate::{RXQLite, /*RXQLiteArgumentValue, */ 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}
22/*
23impl<'r> Decode<'r, RXQLite> for &'r str {
24    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
25        value.text().map(|x| {
26          x.as_str()
27        })
28    }
29}
30*/
31impl 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/*
83impl Type<RXQLite> for Cow<'_, str> {
84    fn type_info() -> RXQLiteTypeInfo {
85        <&str as Type<RXQLite>>::type_info()
86    }
87
88    fn compatible(ty: &RXQLiteTypeInfo) -> bool {
89        <&str as Type<RXQLite>>::compatible(ty)
90    }
91}
92
93impl<'q> Encode<'q, RXQLite> for Cow<'q, str> {
94    fn encode(self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
95        args.push(rxqlite_common::Value::String(self.to_string()));
96
97        IsNull::No
98    }
99
100    fn encode_by_ref(&self, args: &mut Vec<rxqlite_common::Value>) -> IsNull {
101        args.push(rxqlite_common::Value::String(self.to_string()));
102
103        IsNull::No
104    }
105}
106
107impl<'r> Decode<'r, RXQLite> for Cow<'r, str> {
108    fn decode(value: RXQLiteValueRef<'r>) -> Result<Self, BoxDynError> {
109        value.text().map(Cow::Borrowed)
110    }
111}
112*/