Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions source/postcard/src/ser/flavors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,25 @@ impl IndexMut<usize> for Slice<'_> {
}

/// Wrapper over a [`core::iter::Extend<u8>`] that implements the flavor trait
pub struct ExtendFlavor<T> {
iter: T,
pub struct ExtendFlavor<'a, T> {
iter: &'a mut T,
}

impl<T> ExtendFlavor<T>
impl<'a, T> ExtendFlavor<'a, T>
where
T: core::iter::Extend<u8>,
{
/// Create a new [`Self`] flavor from a given [`core::iter::Extend<u8>`]
pub fn new(iter: T) -> Self {
pub fn new(iter: &'a mut T) -> Self {
Self { iter }
}
}

impl<T> Flavor for ExtendFlavor<T>
impl<T> Flavor for ExtendFlavor<'_, T>
where
T: core::iter::Extend<u8>,
{
type Output = T;
type Output = ();

#[inline(always)]
fn try_push(&mut self, data: u8) -> Result<()> {
Expand All @@ -246,7 +246,7 @@ where
}

fn finalize(self) -> Result<Self::Output> {
Ok(self.iter)
Ok(())
}
}

Expand Down
6 changes: 3 additions & 3 deletions source/postcard/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ where
/// use postcard::to_extend;
/// let mut vec = Vec::new();
///
/// let ser = to_extend(&true, vec).unwrap();
/// let vec = to_extend("Hi!", ser).unwrap();
/// to_extend(&true, &mut vec).unwrap();
/// to_extend("Hi!", &mut vec).unwrap();
/// assert_eq!(&vec[0..5], &[0x01, 0x03, b'H', b'i', b'!']);
/// ```
pub fn to_extend<T, W>(value: &T, writer: W) -> Result<W>
pub fn to_extend<T, W>(value: &T, writer: &mut W) -> Result<()>
where
T: Serialize + ?Sized,
W: core::iter::Extend<u8>,
Expand Down