| 1 | use bytes::BytesMut; |
| 2 | use postgres_protocol::types; |
| 3 | use std::error::Error; |
| 4 | use uuid_08::Uuid; |
| 5 | |
| 6 | use crate::{FromSql, IsNull, ToSql, Type}; |
| 7 | |
| 8 | impl<'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 | |
| 17 | impl 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 | } |