Skip to main content

ObjectBody

Struct ObjectBody 

Source
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<'_>

Source

pub fn entry<T>(&mut self, key: &str, value: &T) -> StructResult<()>
where T: Serialize + ?Sized,

Write one "key": value entry.

Source

pub fn entry_with<F>(&mut self, key: &str, f: F) -> StructResult<()>
where F: FnOnce(&mut ResponseBody<'_>) -> 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.

Source

pub fn entry_try_with<F>(&mut self, key: &str, f: F) -> Option<StructResult<()>>
where F: FnOnce(&mut ResponseBody<'_>) -> 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.

Source

pub fn finish(self)

Close the object.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for ObjectBody<'a>

§

impl<'a> Freeze for ObjectBody<'a>

§

impl<'a> RefUnwindSafe for ObjectBody<'a>

§

impl<'a> Send for ObjectBody<'a>

§

impl<'a> Sync for ObjectBody<'a>

§

impl<'a> Unpin for ObjectBody<'a>

§

impl<'a> UnsafeUnpin for ObjectBody<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.