| 1 | use bytes::BytesMut; |
| 2 | use smol_str_01::SmolStr; |
| 3 | use std::error::Error; |
| 4 | |
| 5 | use crate::{FromSql, IsNull, ToSql, Type}; |
| 6 | |
| 7 | impl<'a> FromSql<'a> for SmolStr { |
| 8 | fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<SmolStr, Box<dyn Error + Sync + Send>> { |
| 9 | <&str as FromSql>::from_sql(ty, raw).map(SmolStr::from) |
| 10 | } |
| 11 | |
| 12 | fn accepts(ty: &Type) -> bool { |
| 13 | <&str as FromSql>::accepts(ty) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | impl ToSql for SmolStr { |
| 18 | fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> { |
| 19 | <&str as ToSql>::to_sql(&&**self, ty, w) |
| 20 | } |
| 21 | |
| 22 | fn accepts(ty: &Type) -> bool { |
| 23 | <&str as ToSql>::accepts(ty) |
| 24 | } |
| 25 | |
| 26 | to_sql_checked!(); |
| 27 | } |