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