Skip to content

Commit cff971d

Browse files
committed
Fix suggestions.
1 parent 7699c78 commit cff971d

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

postgres-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ uuid-1 = { version = "1.0", package = "uuid", optional = true }
4949
time-02 = { version = "0.2", package = "time", optional = true }
5050
time-03 = { version = "0.3", package = "time", default-features = false, optional = true }
5151

52-
smol_str = { version = "0.1.23", default-features = false, optional = true }
52+
smol_str-01 = { version = "0.1.23", package = "smol_str", default-features = false, optional = true }

postgres-types/src/lib.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ pub use pg_lsn::PgLsn;
155155

156156
pub use crate::special::{Date, Timestamp};
157157
use bytes::BytesMut;
158-
use smol_str::SmolStr;
159158

160159
// Number of seconds from 1970-01-01 to 2000-01-01
161160
const TIME_SEC_CONVERSION: u64 = 946_684_800;
@@ -233,6 +232,8 @@ mod time_03;
233232
mod uuid_08;
234233
#[cfg(feature = "with-uuid-1")]
235234
mod uuid_1;
235+
#[cfg(feature = "smol_str-01")]
236+
mod smol_str_01;
236237

237238
// The time::{date, time} macros produce compile errors if the crate package is renamed.
238239
#[cfg(feature = "with-time-0_2")]
@@ -444,6 +445,9 @@ impl WrongType {
444445
/// | `eui48::MacAddress` | MACADDR |
445446
/// | `cidr::InetCidr` | CIDR |
446447
/// | `cidr::InetAddr` | INET |
448+
/// | `smol_str::SmolStr` | VARCHAR, CHAR(n), TEXT, CITEXT, |
449+
/// | | NAME, UNKNOWN, LTREE, LQUERY, |
450+
/// | | LTXTQUERY |
447451
///
448452
/// # Nullability
449453
///
@@ -630,18 +634,6 @@ impl<'a> FromSql<'a> for Box<str> {
630634
}
631635
}
632636

633-
#[cfg(feature = "smol_str")]
634-
impl<'a> FromSql<'a> for smol_str::SmolStr {
635-
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<SmolStr, Box<dyn Error + Sync + Send>> {
636-
<&str as FromSql>::from_sql(ty, raw)
637-
.map(SmolStr::from)
638-
}
639-
640-
fn accepts(ty: &Type) -> bool {
641-
<&str as FromSql>::accepts(ty)
642-
}
643-
}
644-
645637
impl<'a> FromSql<'a> for &'a str {
646638
fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<&'a str, Box<dyn Error + Sync + Send>> {
647639
match *ty {
@@ -1042,19 +1034,6 @@ impl ToSql for Box<str> {
10421034
to_sql_checked!();
10431035
}
10441036

1045-
#[cfg(feature = "smol_str")]
1046-
impl ToSql for smol_str::SmolStr {
1047-
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
1048-
<&str as ToSql>::to_sql(&&**self, ty, w)
1049-
}
1050-
1051-
fn accepts(ty: &Type) -> bool {
1052-
<&str as ToSql>::accepts(ty)
1053-
}
1054-
1055-
to_sql_checked!();
1056-
}
1057-
10581037
macro_rules! simple_to {
10591038
($t:ty, $f:ident, $($expected:ident),+) => {
10601039
impl ToSql for $t {

postgres-types/src/smol_str_01.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

0 commit comments

Comments
 (0)