fix: tweak bstr and git2 Encode impls

This commit is contained in:
Ryan Leckey 2020-12-18 21:56:29 -08:00
parent 716517a84f
commit 4ee1727ba6
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9
3 changed files with 17 additions and 7 deletions

View File

@ -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<DB> Type<DB> 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 <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNull {
<&[u8] as Encode<DB>>::encode(self.as_bytes(), buf)
}
}
impl<'q, DB: Database> Encode<'q, DB> for BString
where
DB: Database,
[u8]: Encode<'q, DB>,
Vec<u8>: Encode<'q, DB>,
{
fn encode_by_ref(&self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNull {
<[u8] as Encode<DB>>::encode_by_ref(self.as_bytes(), buf)
<Vec<u8> as Encode<DB>>::encode(self.as_bytes().to_vec(), buf)
}
}

View File

@ -34,9 +34,9 @@ where
impl<'q, DB: Database> Encode<'q, DB> for Oid
where
DB: Database,
[u8]: Encode<'q, DB>,
Vec<u8>: Encode<'q, DB>,
{
fn encode_by_ref(&self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNull {
<[u8] as Encode<DB>>::encode_by_ref(self.as_bytes(), buf)
<Vec<u8> as Encode<DB>>::encode(self.as_bytes().to_vec(), buf)
}
}

View File

@ -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")))]