diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index 2a953db2..84354cf3 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -584,6 +584,18 @@ impl<'a> FromSql<'a> for String { } } +impl<'a> FromSql<'a> for Box { + fn from_sql(_: &Type, raw: &'a [u8]) -> Result, Box> { + types::text_from_sql(raw) + .map(ToString::to_string) + .map(String::into_boxed_str) + } + + fn accepts(ty: &Type) -> bool { + <&str as FromSql>::accepts(ty) + } +} + impl<'a> FromSql<'a> for &'a str { fn from_sql(_: &Type, raw: &'a [u8]) -> Result<&'a str, Box> { types::text_from_sql(raw) @@ -933,6 +945,18 @@ impl ToSql for String { to_sql_checked!(); } +impl ToSql for Box { + fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result> { + <&str as ToSql>::to_sql(&&**self, ty, w) + } + + fn accepts(ty: &Type) -> bool { + <&str as ToSql>::accepts(ty) + } + + to_sql_checked!(); +} + macro_rules! simple_to { ($t:ty, $f:ident, $($expected:ident),+) => { impl ToSql for $t {