pub fn append<T: Write + ?Sized>(value: &T, out: &mut Vec<u8>)Expand description
Serialize a value after what a buffer already holds.
write_into replaces the buffer’s contents, so a document that has to sit
behind a header has until now needed a second buffer and a copy out of it.
This writes past what is there instead, into the one allocation.
The bytes already in the buffer also count as the part of the document in
front of this value, so an implementation that positions its own bytes from
Writer::offset lands them where they will really sit. size_after is
the matching measurement: size_after(value, out.len()) is what this will
add.
They are not lost either, if writing the value panics: out comes back
holding exactly what it held before the call. A Write impl may panic by
design, an adapter whose target has values it cannot encode being told to
substitute or panic, and the bytes in front are the caller’s rather than
this call’s to spend. write_into makes the other bargain, its buffer
being one it was asked to overwrite.