Merge pull request #919 from BratSinot/smol_str
Add FromSql / ToSql for smol_str::SmolStr.
This commit is contained in:
commit
a3c0e52a9c
@ -48,3 +48,5 @@ uuid-08 = { version = "0.8", package = "uuid", optional = true }
|
||||
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 }
|
||||
|
@ -224,6 +224,8 @@ mod geo_types_06;
|
||||
mod geo_types_07;
|
||||
#[cfg(feature = "with-serde_json-1")]
|
||||
mod serde_json_1;
|
||||
#[cfg(feature = "smol_str-01")]
|
||||
mod smol_str_01;
|
||||
#[cfg(feature = "with-time-0_2")]
|
||||
mod time_02;
|
||||
#[cfg(feature = "with-time-0_3")]
|
||||
@ -443,6 +445,9 @@ impl WrongType {
|
||||
/// | `eui48::MacAddress` | MACADDR |
|
||||
/// | `cidr::InetCidr` | CIDR |
|
||||
/// | `cidr::InetAddr` | INET |
|
||||
/// | `smol_str::SmolStr` | VARCHAR, CHAR(n), TEXT, CITEXT, |
|
||||
/// | | NAME, UNKNOWN, LTREE, LQUERY, |
|
||||
/// | | LTXTQUERY |
|
||||
///
|
||||
/// # Nullability
|
||||
///
|
||||
|
27
postgres-types/src/smol_str_01.rs
Normal file
27
postgres-types/src/smol_str_01.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use bytes::BytesMut;
|
||||
use smol_str_01::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<SmolStr, Box<dyn Error + Sync + Send>> {
|
||||
<&str as FromSql>::from_sql(ty, raw).map(SmolStr::from)
|
||||
}
|
||||
|
||||
fn accepts(ty: &Type) -> bool {
|
||||
<&str as FromSql>::accepts(ty)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql for SmolStr {
|
||||
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
|
||||
<&str as ToSql>::to_sql(&&**self, ty, w)
|
||||
}
|
||||
|
||||
fn accepts(ty: &Type) -> bool {
|
||||
<&str as ToSql>::accepts(ty)
|
||||
}
|
||||
|
||||
to_sql_checked!();
|
||||
}
|
Loading…
Reference in New Issue
Block a user