Skip to main content

from_reader

Function from_reader 

Source
pub fn from_reader<T, R>(reader: R) -> StreamResult<T>
where T: for<'de> Read<'de> + Default, R: Read,
Expand description

Parse one BEVE document from an io::Read.

The reader is drained into memory and then parsed, so this is a convenience rather than a way to bound memory: the encoded document is held whole, and then the value built from it is held beside it.

Two things bound it instead, and both want the top level to be an array, that being where a document divides. Documents::array hands out one element at a time however long the array runs, converting a stored width into the one you asked for as it goes. read_array_into is the same bound without the per-element work: where the stored element type is already T’s, the payload goes from the reader into the vector’s own memory, which is the multi-gigabyte case. Documents::values is neither, buffering one whole document exactly as this call does.

A document whose top level is not an array offers no smaller unit to be read in, and this is the call for it.

T may not borrow from the input, since the buffer does not outlive the call. Use from_slice over a buffer you keep for the borrowing form.