pub struct ObjectBody<'a> { /* private fields */ }Expand description
A JSON object body being written key by key. Created by
ResponseBody::object; call finish to close it.
An entry that fails — or that entry_try_with
declines — rewinds the buffer past the opening brace, so a partly written
object is never left behind for a caller that recovers from it. Dropping
without calling finish is the same situation and leaves
nothing behind either, since both ways out without finishing have already
rewound.
Implementations§
Source§impl ObjectBody<'_>
impl ObjectBody<'_>
Sourcepub fn entry<T>(&mut self, key: &str, value: &T) -> StructResult<()>
pub fn entry<T>(&mut self, key: &str, value: &T) -> StructResult<()>
Write one "key": value entry.
Sourcepub fn entry_with<F>(&mut self, key: &str, f: F) -> StructResult<()>
pub fn entry_with<F>(&mut self, key: &str, f: F) -> StructResult<()>
Write one "key": <value> entry whose value is produced by f, for a
nested RepeStruct that fills the body itself.
The body handed to f is marked as nested: the enclosing frame is
already JSON, so a ResponseBody::write_typed_slice inside it falls
back to a JSON array rather than switching the frame to BEVE.
Sourcepub fn entry_try_with<F>(&mut self, key: &str, f: F) -> Option<StructResult<()>>
pub fn entry_try_with<F>(&mut self, key: &str, f: F) -> Option<StructResult<()>>
entry_with for a value the source may decline to
produce, as RepeStruct::repe_shared_into declines a path that needs
exclusive access.
None rewinds the whole object, exactly as an Err does, so a caller
that declines in turn leaves the buffer as it found it without a second
step. Dropping the object without calling finish then
leaves nothing behind, because the only ways out without finishing are
an error and a decline, and both have already rewound.