1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
use bytes::BytesMut; use std::error::Error; #[cfg(feature = "psql")] use postgres::types::{FromSql, IsNull, ToSql, Type}; use crate::syn::null::Null; #[cfg(all(feature = "async-psql", not(feature = "psql")))] use tokio_postgres::types::{FromSql, IsNull, ToSql, Type}; impl<'a> FromSql<'a> for Null { fn from_sql(_ty: &Type, _raw: &'a [u8]) -> Result<Self, Box<dyn Error + Sync + Send>> { Ok(Null) } fn accepts(ty: &Type) -> bool { <Option<Vec<u8>> as FromSql>::accepts(ty) } } impl ToSql for Null { fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> where Self: Sized, { <Option<Vec<u8>> as ToSql>::to_sql(&None, ty, out) } fn accepts(ty: &Type) -> bool where Self: Sized, { <Option<Vec<u8>> as ToSql>::accepts(ty) } fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>> { <Option<Vec<u8>> as ToSql>::to_sql_checked(&None, ty, out) } }