pub struct Builder { /* private fields */ }Expand description
A value under construction.
Reusable: Builder::finish hands back the bytes and Builder::clear
puts it back to empty with its buffers intact, so a loop over a million
documents allocates a handful of times rather than a million.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn with_capacity(bytes: usize) -> Builder
pub fn with_capacity(bytes: usize) -> Builder
Empty, with room for bytes of value already reserved.
Sourcepub fn finish(&mut self) -> Result<&[u8], Error>
pub fn finish(&mut self) -> Result<&[u8], Error>
The finished value.
An error here means the value is not finished: a container was begun and not ended, a key was written with no value after it, or nothing was written at all.
Sourcepub fn int(&mut self, v: i64) -> Result<(), Error>
pub fn int(&mut self, v: i64) -> Result<(), Error>
Write an integer, in as few bytes as it fits in.
Sourcepub fn text_bytes(&mut self, v: &[u8]) -> Result<(), Error>
pub fn text_bytes(&mut self, v: &[u8]) -> Result<(), Error>
Write a string that is already bytes.
The bytes are stored as they are and are not checked, so a caller that
hands over something that is not UTF-8 gets a document whose
Value::as_text answers None where it should have answered a
string. It exists because RESP carries strings as bytes and re-checking
what a client already sent is a copy nobody asked for.
Sourcepub fn embed(&mut self, v: &Value<'_>) -> Result<(), Error>
pub fn embed(&mut self, v: &Value<'_>) -> Result<(), Error>
Copy a value that is already encoded.
This is how a path update writes the parts of a document it is not changing: they are already in the right form, so they are memcpy and not a re-encode.
Sourcepub fn begin_object(&mut self) -> Result<(), Error>
pub fn begin_object(&mut self) -> Result<(), Error>
Begin an object. Every value inside it needs a Builder::key first.
Sourcepub fn begin_object_interned(&mut self) -> Result<(), Error>
pub fn begin_object_interned(&mut self) -> Result<(), Error>
Begin an object whose keys are ids from a collection’s intern table.
Every value inside it needs a Builder::key_id first. This is what a
typed collection writes, and it is where the size of a document
collection mostly goes: the same twenty field names on every document
cost two bytes each here instead of their bytes.
Sourcepub fn begin_array(&mut self) -> Result<(), Error>
pub fn begin_array(&mut self) -> Result<(), Error>
Begin an array.
Sourcepub fn end_object(&mut self) -> Result<(), Error>
pub fn end_object(&mut self) -> Result<(), Error>
End the object begun by the matching Builder::begin_object.
Sourcepub fn end_array(&mut self) -> Result<(), Error>
pub fn end_array(&mut self) -> Result<(), Error>
End the array begun by the matching Builder::begin_array.