From 0c249267b8e4d610b03922a9e80ceb10fa1760f8 Mon Sep 17 00:00:00 2001
From: novacrazy <novacrazy@gmail.com>
Date: Tue, 16 Jan 2024 13:43:00 -0600
Subject: [PATCH 1/4] Add smol_str 0.2 support

---
 postgres-types/Cargo.toml         |  2 ++
 postgres-types/src/lib.rs         |  2 ++
 postgres-types/src/smol_str_02.rs | 27 +++++++++++++++++++++++++++
 3 files changed, 31 insertions(+)
 create mode 100644 postgres-types/src/smol_str_02.rs

diff --git a/postgres-types/Cargo.toml b/postgres-types/Cargo.toml
index 941f4fcc4..90a9c4fba 100644
--- a/postgres-types/Cargo.toml
+++ b/postgres-types/Cargo.toml
@@ -24,6 +24,7 @@ with-geo-types-0_7 = ["geo-types-0_7"]
 with-jiff-0_1 = ["jiff-01"]
 with-serde_json-1 = ["serde-1", "serde_json-1"]
 with-smol_str-01 = ["smol_str-01"]
+with-smol_str-02 = ["smol_str-02"]
 with-uuid-0_8 = ["uuid-08"]
 with-uuid-1 = ["uuid-1"]
 with-time-0_2 = ["time-02"]
@@ -55,3 +56,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-01 = { version = "0.1.23", package = "smol_str", default-features = false, optional = true }
+smol_str-02 = { version = "0.2", package = "smol_str", default-features = false, optional = true }
diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs
index 6ad2eff50..4a643b9a9 100644
--- a/postgres-types/src/lib.rs
+++ b/postgres-types/src/lib.rs
@@ -282,6 +282,8 @@ mod jiff_01;
 mod serde_json_1;
 #[cfg(feature = "with-smol_str-01")]
 mod smol_str_01;
+#[cfg(feature = "with-smol_str-02")]
+mod smol_str_02;
 #[cfg(feature = "with-time-0_2")]
 mod time_02;
 #[cfg(feature = "with-time-0_3")]
diff --git a/postgres-types/src/smol_str_02.rs b/postgres-types/src/smol_str_02.rs
new file mode 100644
index 000000000..757dccb91
--- /dev/null
+++ b/postgres-types/src/smol_str_02.rs
@@ -0,0 +1,27 @@
+use bytes::BytesMut;
+use smol_str_02::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<Self, Box<dyn Error + Sync + Send>> {
+        Ok(SmolStr::new(<&str as FromSql>::from_sql(ty, raw)?))
+    }
+
+    fn accepts(ty: &Type) -> bool {
+        <&str as FromSql>::accepts(ty)
+    }
+}
+
+impl ToSql for SmolStr {
+    fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
+        <&str as ToSql>::to_sql(&self.as_str(), ty, out)
+    }
+
+    fn accepts(ty: &Type) -> bool {
+        <&str as ToSql>::accepts(ty)
+    }
+
+    to_sql_checked!();
+}

From f52f821e2a06d797c477627a748228caa4097597 Mon Sep 17 00:00:00 2001
From: novacrazy <novacrazy@gmail.com>
Date: Tue, 16 Jan 2024 13:49:32 -0600
Subject: [PATCH 2/4] Use map instead of ?

---
 postgres-types/src/smol_str_02.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/postgres-types/src/smol_str_02.rs b/postgres-types/src/smol_str_02.rs
index 757dccb91..3c6d1a6ed 100644
--- a/postgres-types/src/smol_str_02.rs
+++ b/postgres-types/src/smol_str_02.rs
@@ -6,7 +6,7 @@ use crate::{FromSql, IsNull, ToSql, Type};
 
 impl<'a> FromSql<'a> for SmolStr {
     fn from_sql(ty: &Type, raw: &'a [u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
-        Ok(SmolStr::new(<&str as FromSql>::from_sql(ty, raw)?))
+        <&str as FromSql>::from_sql(ty, raw).map(SmolStr::new)
     }
 
     fn accepts(ty: &Type) -> bool {

From 798f81be481de2bb3bd805876e62e9a6ee8543a8 Mon Sep 17 00:00:00 2001
From: novacrazy <novacrazy@gmail.com>
Date: Fri, 6 Sep 2024 21:31:09 -0500
Subject: [PATCH 3/4] smol_str 0.3 support

---
 postgres-types/Cargo.toml         |  2 ++
 postgres-types/src/lib.rs         |  2 ++
 postgres-types/src/smol_str_03.rs | 31 +++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
 create mode 100644 postgres-types/src/smol_str_03.rs

diff --git a/postgres-types/Cargo.toml b/postgres-types/Cargo.toml
index 90a9c4fba..c9fd10a9b 100644
--- a/postgres-types/Cargo.toml
+++ b/postgres-types/Cargo.toml
@@ -25,6 +25,7 @@ with-jiff-0_1 = ["jiff-01"]
 with-serde_json-1 = ["serde-1", "serde_json-1"]
 with-smol_str-01 = ["smol_str-01"]
 with-smol_str-02 = ["smol_str-02"]
+with-smol_str-03 = ["smol_str-03"]
 with-uuid-0_8 = ["uuid-08"]
 with-uuid-1 = ["uuid-1"]
 with-time-0_2 = ["time-02"]
@@ -57,3 +58,4 @@ time-02 = { version = "0.2", package = "time", optional = true }
 time-03 = { version = "0.3", package = "time", default-features = false, optional = true }
 smol_str-01 = { version = "0.1.23", package = "smol_str", default-features = false, optional = true }
 smol_str-02 = { version = "0.2", package = "smol_str", default-features = false, optional = true }
+smol_str-03 = { version = "0.3", package = "smol_str", default-features = false, optional = true }
diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs
index 4a643b9a9..f61dec686 100644
--- a/postgres-types/src/lib.rs
+++ b/postgres-types/src/lib.rs
@@ -284,6 +284,8 @@ mod serde_json_1;
 mod smol_str_01;
 #[cfg(feature = "with-smol_str-02")]
 mod smol_str_02;
+#[cfg(feature = "with-smol_str-03")]
+mod smol_str_03;
 #[cfg(feature = "with-time-0_2")]
 mod time_02;
 #[cfg(feature = "with-time-0_3")]
diff --git a/postgres-types/src/smol_str_03.rs b/postgres-types/src/smol_str_03.rs
new file mode 100644
index 000000000..b746bb245
--- /dev/null
+++ b/postgres-types/src/smol_str_03.rs
@@ -0,0 +1,31 @@
+use bytes::BytesMut;
+use smol_str_03::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<Self, Box<dyn Error + Sync + Send>> {
+        <&str as FromSql>::from_sql(ty, raw).map(SmolStr::new)
+    }
+
+    fn accepts(ty: &Type) -> bool {
+        <&str as FromSql>::accepts(ty)
+    }
+}
+
+impl ToSql for SmolStr {
+    fn to_sql(
+        &self,
+        ty: &Type,
+        out: &mut BytesMut,
+    ) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
+        <&str as ToSql>::to_sql(&self.as_str(), ty, out)
+    }
+
+    fn accepts(ty: &Type) -> bool {
+        <&str as ToSql>::accepts(ty)
+    }
+
+    to_sql_checked!();
+}

From 42e59fe5f4db3944e949ff4efc5ffe9eb8cce36a Mon Sep 17 00:00:00 2001
From: novacrazy <novacrazy@gmail.com>
Date: Fri, 6 Sep 2024 21:33:16 -0500
Subject: [PATCH 4/4] Formatting

---
 postgres-types/src/smol_str_02.rs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/postgres-types/src/smol_str_02.rs b/postgres-types/src/smol_str_02.rs
index 3c6d1a6ed..e5849a2ac 100644
--- a/postgres-types/src/smol_str_02.rs
+++ b/postgres-types/src/smol_str_02.rs
@@ -15,7 +15,11 @@ impl<'a> FromSql<'a> for SmolStr {
 }
 
 impl ToSql for SmolStr {
-    fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
+    fn to_sql(
+        &self,
+        ty: &Type,
+        out: &mut BytesMut,
+    ) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
         <&str as ToSql>::to_sql(&self.as_str(), ty, out)
     }