rbdc_pg/types/
string.rs

1use crate::arguments::PgArgumentBuffer;
2use crate::type_info::PgTypeInfo;
3use crate::types::decode::Decode;
4use crate::types::encode::{Encode, IsNull};
5use crate::types::TypeInfo;
6use crate::value::PgValue;
7use rbdc::Error;
8
9impl Decode for String {
10    fn decode(value: PgValue) -> Result<Self, Error> {
11        Ok(value.as_str()?.to_owned())
12    }
13}
14
15impl Encode for String {
16    fn encode(self, buf: &mut PgArgumentBuffer) -> Result<IsNull, Error> {
17        buf.extend(self.into_bytes());
18        Ok(IsNull::No)
19    }
20}
21
22impl TypeInfo for String {
23    fn type_info(&self) -> PgTypeInfo {
24        PgTypeInfo::VARCHAR
25    }
26}