Skip to main content

write_into

Function write_into 

Source
pub fn write_into<T: Write + ?Sized>(value: &T, out: &mut Vec<u8>)
Expand description

Serialize into an existing buffer, replacing its contents and keeping its allocation.

Examples found in repository?
examples/beve.rs (line 63)
58fn send_frames(values: &[Run], sink: &mut impl std::io::Write) -> std::io::Result<()> {
59    let mut body = Vec::new();
60    for value in values {
61        // Clears the buffer and keeps its allocation, so after an iteration or
62        // two this loop stops allocating altogether.
63        structio::write_beve_into(value, &mut body);
64        sink.write_all(&(body.len() as u32).to_le_bytes())?;
65        sink.write_all(&body)?;
66    }
67    Ok(())
68}