diff --git a/sqlx-core/src/types/bstr.rs b/sqlx-core/src/types/bstr.rs index db1e8f6e..976357d3 100644 --- a/sqlx-core/src/types/bstr.rs +++ b/sqlx-core/src/types/bstr.rs @@ -5,7 +5,7 @@ use crate::encode::{Encode, IsNull}; use crate::error::BoxDynError; use crate::types::Type; -pub use bstr::{BString, ByteSlice}; +pub use bstr::{BString, BStr, ByteSlice}; impl Type for BString where @@ -31,12 +31,22 @@ where } } +impl<'q, DB: Database> Encode<'q, DB> for &'q BStr +where + DB: Database, + &'q [u8]: Encode<'q, DB>, +{ + fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { + <&[u8] as Encode>::encode(self.as_bytes(), buf) + } +} + impl<'q, DB: Database> Encode<'q, DB> for BString where DB: Database, - [u8]: Encode<'q, DB>, + Vec: Encode<'q, DB>, { fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { - <[u8] as Encode>::encode_by_ref(self.as_bytes(), buf) + as Encode>::encode(self.as_bytes().to_vec(), buf) } } diff --git a/sqlx-core/src/types/git2.rs b/sqlx-core/src/types/git2.rs index f4fd576a..38964103 100644 --- a/sqlx-core/src/types/git2.rs +++ b/sqlx-core/src/types/git2.rs @@ -34,9 +34,9 @@ where impl<'q, DB: Database> Encode<'q, DB> for Oid where DB: Database, - [u8]: Encode<'q, DB>, + Vec: Encode<'q, DB>, { fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> IsNull { - <[u8] as Encode>::encode_by_ref(self.as_bytes(), buf) + as Encode>::encode(self.as_bytes().to_vec(), buf) } } diff --git a/sqlx-core/src/types/mod.rs b/sqlx-core/src/types/mod.rs index 76c49fb1..cf1e3563 100644 --- a/sqlx-core/src/types/mod.rs +++ b/sqlx-core/src/types/mod.rs @@ -22,11 +22,11 @@ use crate::database::Database; #[cfg(feature = "bstr")] #[cfg_attr(docsrs, doc(cfg(feature = "bstr")))] -mod bstr; +pub mod bstr; #[cfg(feature = "git2")] #[cfg_attr(docsrs, doc(cfg(feature = "git2")))] -mod git2; +pub mod git2; #[cfg(feature = "json")] #[cfg_attr(docsrs, doc(cfg(feature = "json")))]