diff --git a/postgres-types/Cargo.toml b/postgres-types/Cargo.toml index 83ff718a..d8464186 100644 --- a/postgres-types/Cargo.toml +++ b/postgres-types/Cargo.toml @@ -49,4 +49,4 @@ uuid-1 = { version = "1.0", package = "uuid", optional = true } time-02 = { version = "0.2", package = "time", optional = true } time-03 = { version = "0.3", package = "time", default-features = false, optional = true } -smol_str = { version = "0.1.23", default-features = false, optional = true } +smol_str-01 = { version = "0.1.23", package = "smol_str", default-features = false, optional = true } diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index 3933f34c..c06a2fb4 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -155,7 +155,6 @@ pub use pg_lsn::PgLsn; pub use crate::special::{Date, Timestamp}; use bytes::BytesMut; -use smol_str::SmolStr; // Number of seconds from 1970-01-01 to 2000-01-01 const TIME_SEC_CONVERSION: u64 = 946_684_800; @@ -233,6 +232,8 @@ mod time_03; mod uuid_08; #[cfg(feature = "with-uuid-1")] mod uuid_1; +#[cfg(feature = "smol_str-01")] +mod smol_str_01; // The time::{date, time} macros produce compile errors if the crate package is renamed. #[cfg(feature = "with-time-0_2")] @@ -444,6 +445,9 @@ impl WrongType { /// | `eui48::MacAddress` | MACADDR | /// | `cidr::InetCidr` | CIDR | /// | `cidr::InetAddr` | INET | +/// | `smol_str::SmolStr` | VARCHAR, CHAR(n), TEXT, CITEXT, | +/// | | NAME, UNKNOWN, LTREE, LQUERY, | +/// | | LTXTQUERY | /// /// # Nullability /// @@ -630,18 +634,6 @@ impl<'a> FromSql<'a> for Box { } } -#[cfg(feature = "smol_str")] -impl<'a> FromSql<'a> for smol_str::SmolStr { - fn from_sql(ty: &Type, raw: &'a [u8]) -> Result> { - <&str as FromSql>::from_sql(ty, raw) - .map(SmolStr::from) - } - - fn accepts(ty: &Type) -> bool { - <&str as FromSql>::accepts(ty) - } -} - impl<'a> FromSql<'a> for &'a str { fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<&'a str, Box> { match *ty { @@ -1042,19 +1034,6 @@ impl ToSql for Box { to_sql_checked!(); } -#[cfg(feature = "smol_str")] -impl ToSql for smol_str::SmolStr { - 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 { diff --git a/postgres-types/src/smol_str_01.rs b/postgres-types/src/smol_str_01.rs new file mode 100644 index 00000000..a0d024ce --- /dev/null +++ b/postgres-types/src/smol_str_01.rs @@ -0,0 +1,27 @@ +use bytes::BytesMut; +use smol_str_01::SmolStr; +use std::error::Error; + +use crate::{FromSql, IsNull, ToSql, Type}; + +impl<'a> FromSql<'a> for SmolStr { + fn from_sql(ty: &Type, raw: &'a [u8]) -> Result> { + <&str as FromSql>::from_sql(ty, raw).map(SmolStr::from) + } + + fn accepts(ty: &Type) -> bool { + <&str as FromSql>::accepts(ty) + } +} + +impl ToSql for SmolStr { + 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!(); +}