postgres_types/
uuid_1.rs

1use bytes::BytesMut;
2use postgres_protocol::types;
3use std::error::Error;
4use uuid_1::Uuid;
5
6use crate::{FromSql, IsNull, ToSql, Type};
7
8impl<'a> FromSql<'a> for Uuid {
9    fn from_sql(_: &Type, raw: &[u8]) -> Result<Uuid, Box<dyn Error + Sync + Send>> {
10        let bytes = types::uuid_from_sql(raw)?;
11        Ok(Uuid::from_bytes(bytes))
12    }
13
14    accepts!(UUID);
15}
16
17impl ToSql for Uuid {
18    fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
19        types::uuid_to_sql(*self.as_bytes(), w);
20        Ok(IsNull::No)
21    }
22
23    accepts!(UUID);
24    to_sql_checked!();
25}