Skip to content

Commit

Permalink
Allow generics in impl_borrow_decode (bincode-org#635)
Browse files Browse the repository at this point in the history
* Allow generics in impl_borrow_decode

* Use impl_borrow_decode for PhantomData

* Update impls.rs

* Update mod.rs
  • Loading branch information
dullbananas committed Jun 19, 2023
1 parent f9f87ea commit 224e412
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,7 @@ impl<T> Decode for core::marker::PhantomData<T> {
Ok(core::marker::PhantomData)
}
}
impl<'de, T> BorrowDecode<'de> for core::marker::PhantomData<T> {
fn borrow_decode<D: BorrowDecoder<'de>>(_: &mut D) -> Result<Self, DecodeError> {
Ok(core::marker::PhantomData)
}
}
impl_borrow_decode!(core::marker::PhantomData<T>, T);

impl<T> Decode for Option<T>
where
Expand Down
4 changes: 2 additions & 2 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub trait BorrowDecode<'de>: Sized {
/// Helper macro to implement `BorrowDecode` for any type that implements `Decode`.
#[macro_export]
macro_rules! impl_borrow_decode {
($ty:ty) => {
impl<'de> $crate::BorrowDecode<'de> for $ty {
($ty:ty $(, $param:ident),*) => {
impl<'de $(, $param)*> $crate::BorrowDecode<'de> for $ty {
fn borrow_decode<D: $crate::de::BorrowDecoder<'de>>(
decoder: &mut D,
) -> core::result::Result<Self, $crate::error::DecodeError> {
Expand Down

0 comments on commit 224e412

Please sign in to comment.