-
-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(); | ||
} |