Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smol_str 0.2 and 0.3 support #1095

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions postgres-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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-smol_str-03 = ["smol_str-03"]
with-uuid-0_8 = ["uuid-08"]
with-uuid-1 = ["uuid-1"]
with-time-0_2 = ["time-02"]
Expand Down Expand Up @@ -55,3 +57,5 @@ 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 }
smol_str-03 = { version = "0.3", package = "smol_str", default-features = false, optional = true }
4 changes: 4 additions & 0 deletions postgres-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ 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-smol_str-03")]
mod smol_str_03;
#[cfg(feature = "with-time-0_2")]
mod time_02;
#[cfg(feature = "with-time-0_3")]
Expand Down
31 changes: 31 additions & 0 deletions postgres-types/src/smol_str_02.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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>> {
<&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!();
}
31 changes: 31 additions & 0 deletions postgres-types/src/smol_str_03.rs
Original file line number Diff line number Diff line change
@@ -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!();
}
Loading