Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
This commit is contained in:
parent
71657b4f18
commit
abd63166c0
|
@ -149,27 +149,19 @@ impl Vector {
|
||||||
vec.iter().try_for_each(|e| func(&mut writer, e))
|
vec.iter().try_for_each(|e| func(&mut writer, e))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes at most `items_to_write` values from the provided iterator to the stream
|
/// Writes an iterator of values by writing [`CompactSize`]-encoded integer specifying
|
||||||
/// in [`CompactSize`]-prefixed format.
|
/// the length of the iterator to the stream, followed by the encoding of each element
|
||||||
///
|
/// of the iterator as performed by the provided function.
|
||||||
/// If not enough items are available, this will return an error; all available
|
pub fn write_sized<W: Write, E, F, I: Iterator<Item = E> + ExactSizeIterator>(
|
||||||
/// elements will already have been written to the stream but the [`CompactSize`]
|
|
||||||
/// prefix that was written will be incorrect, and so the data written will not be
|
|
||||||
/// able to be correctly decoded as a vector.
|
|
||||||
pub fn write_sized<'a, W: Write, E: 'a, F, I: Iterator<Item = E> + ExactSizeIterator>(
|
|
||||||
mut writer: W,
|
mut writer: W,
|
||||||
items: I,
|
mut items: I,
|
||||||
func: F,
|
func: F,
|
||||||
) -> io::Result<()>
|
) -> io::Result<()>
|
||||||
where
|
where
|
||||||
F: Fn(&mut W, E) -> io::Result<()>,
|
F: Fn(&mut W, E) -> io::Result<()>,
|
||||||
{
|
{
|
||||||
CompactSize::write(&mut writer, items.len())?;
|
CompactSize::write(&mut writer, items.len())?;
|
||||||
for item in items {
|
items.try_for_each(|e| func(&mut writer, e))
|
||||||
func(&mut writer, item)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue