sqlx_xugu/types/
text.rs

1use crate::arguments::XuguArgumentValue;
2use crate::{Xugu, XuguTypeInfo, XuguValueRef};
3use sqlx_core::decode::Decode;
4use sqlx_core::encode::{Encode, IsNull};
5use sqlx_core::error::BoxDynError;
6use sqlx_core::types::{Text, Type};
7use std::fmt::Display;
8use std::str::FromStr;
9
10impl<T> Type<Xugu> for Text<T> {
11    fn type_info() -> XuguTypeInfo {
12        <String as Type<Xugu>>::type_info()
13    }
14
15    fn compatible(ty: &XuguTypeInfo) -> bool {
16        <String as Type<Xugu>>::compatible(ty)
17    }
18}
19
20impl<'q, T> Encode<'q, Xugu> for Text<T>
21where
22    T: Display,
23{
24    fn encode_by_ref(&self, args: &mut Vec<XuguArgumentValue<'q>>) -> Result<IsNull, BoxDynError> {
25        Encode::<Xugu>::encode(self.0.to_string(), args)
26    }
27}
28
29impl<'r, T> Decode<'r, Xugu> for Text<T>
30where
31    T: FromStr,
32    BoxDynError: From<<T as FromStr>::Err>,
33{
34    fn decode(value: XuguValueRef<'r>) -> Result<Self, BoxDynError> {
35        let s: &str = Decode::<Xugu>::decode(value)?;
36        Ok(Self(s.parse()?))
37    }
38}