Skip to content

Commit 798f81b

Browse files
committed
smol_str 0.3 support
1 parent f52f821 commit 798f81b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

postgres-types/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ with-jiff-0_1 = ["jiff-01"]
2525
with-serde_json-1 = ["serde-1", "serde_json-1"]
2626
with-smol_str-01 = ["smol_str-01"]
2727
with-smol_str-02 = ["smol_str-02"]
28+
with-smol_str-03 = ["smol_str-03"]
2829
with-uuid-0_8 = ["uuid-08"]
2930
with-uuid-1 = ["uuid-1"]
3031
with-time-0_2 = ["time-02"]
@@ -57,3 +58,4 @@ time-02 = { version = "0.2", package = "time", optional = true }
5758
time-03 = { version = "0.3", package = "time", default-features = false, optional = true }
5859
smol_str-01 = { version = "0.1.23", package = "smol_str", default-features = false, optional = true }
5960
smol_str-02 = { version = "0.2", package = "smol_str", default-features = false, optional = true }
61+
smol_str-03 = { version = "0.3", package = "smol_str", default-features = false, optional = true }

postgres-types/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ mod serde_json_1;
284284
mod smol_str_01;
285285
#[cfg(feature = "with-smol_str-02")]
286286
mod smol_str_02;
287+
#[cfg(feature = "with-smol_str-03")]
288+
mod smol_str_03;
287289
#[cfg(feature = "with-time-0_2")]
288290
mod time_02;
289291
#[cfg(feature = "with-time-0_3")]

postgres-types/src/smol_str_03.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use bytes::BytesMut;
2+
use smol_str_03::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<Self, Box<dyn Error + Sync + Send>> {
9+
<&str as FromSql>::from_sql(ty, raw).map(SmolStr::new)
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(
19+
&self,
20+
ty: &Type,
21+
out: &mut BytesMut,
22+
) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
23+
<&str as ToSql>::to_sql(&self.as_str(), ty, out)
24+
}
25+
26+
fn accepts(ty: &Type) -> bool {
27+
<&str as ToSql>::accepts(ty)
28+
}
29+
30+
to_sql_checked!();
31+
}

0 commit comments

Comments
 (0)