Skip to content

Commit d61eef2

Browse files
committed
Add smol_str 0.2 support
1 parent e8f44ec commit d61eef2

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

postgres-types/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ with-geo-types-0_6 = ["geo-types-06"]
2222
with-geo-types-0_7 = ["geo-types-0_7"]
2323
with-serde_json-1 = ["serde-1", "serde_json-1"]
2424
with-smol_str-01 = ["smol_str-01"]
25+
with-smol_str-02 = ["smol_str-02"]
2526
with-uuid-0_8 = ["uuid-08"]
2627
with-uuid-1 = ["uuid-1"]
2728
with-time-0_2 = ["time-02"]
@@ -52,3 +53,4 @@ uuid-1 = { version = "1.0", package = "uuid", optional = true }
5253
time-02 = { version = "0.2", package = "time", optional = true }
5354
time-03 = { version = "0.3", package = "time", default-features = false, optional = true }
5455
smol_str-01 = { version = "0.1.23", package = "smol_str", default-features = false, optional = true }
56+
smol_str-02 = { version = "0.2", package = "smol_str", default-features = false, optional = true }

postgres-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ mod geo_types_07;
280280
mod serde_json_1;
281281
#[cfg(feature = "with-smol_str-01")]
282282
mod smol_str_01;
283+
#[cfg(feature = "with-smol_str-02")]
284+
mod smol_str_02;
283285
#[cfg(feature = "with-time-0_2")]
284286
mod time_02;
285287
#[cfg(feature = "with-time-0_3")]

postgres-types/src/smol_str_02.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_02::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+
Ok(SmolStr::new(<&str as FromSql>::from_sql(ty, raw)?))
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, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
19+
<&str as ToSql>::to_sql(&self.as_str(), ty, out)
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)