JsonObject

Struct JsonObject 

Source
pub struct JsonObject<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> { /* private fields */ }
Expand description

A JsonObject is the API for writing a JSON object, i.e. a sequence of key/value pairs. The closing } is written when the JsonObject instance goes out of scope, or when its end() function is called.

For nested objects or arrays, the function calls return new JsonObject or JsonArray instances, respectively. Rust’s type system ensures that applications can only interact with the innermost such instance, and call outer instances only when all nested instances have gone out of scope.

A typical use of the library is to create a JsonWriter and then wrap it in a top-level JsonObject instance.

Implementations§

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn new(writer: &'a mut JsonWriter<'b, W, F, FF>) -> Result<Self, W::Error>

Create a new JsonObject instance. Application code can do this explicitly only initially as a starting point for writing JSON. Nested objects are created by the library.

Source

pub fn write_string_value( &mut self, key: &str, value: &str, ) -> Result<(), W::Error>

Write a key/value pair with element type ‘string’, escaping the provided string value.

Source

pub fn write_bool_value( &mut self, key: &str, value: bool, ) -> Result<(), W::Error>

Write a key/value pair with element type ‘bool’

Source

pub fn write_null_value(&mut self, key: &str) -> Result<(), W::Error>

Write a key with a null literal as its value

Source

pub fn write_f64_value(&mut self, key: &str, value: f64) -> Result<(), W::Error>

Write a key/value pair with an f64 value. If the value is not finite (i.e. infinite or NaN), a null literal is written instead. Different behavior (e.g. leaving out the whole key/value pair for non-finite numbers, representing them in some other way etc.) is the responsibility of application code.

Source

pub fn write_f32_value(&mut self, key: &str, value: f32) -> Result<(), W::Error>

Write a key/value pair with an f32 value. If the value is not finite (i.e. infinite or NaN), a null literal is written instead. Different behavior (e.g. leaving out the whole key/value pair for non-finite numbers, representing them in some other way etc.) is the responsibility of application code.

Source

pub fn start_object<'c, 'x>( &'x mut self, key: &str, ) -> Result<JsonObject<'c, 'b, W, F, FF>, W::Error>
where 'a: 'c, 'x: 'c,

Start a nested object under a given key. This function returns a new JsonObject instance for writing elements to the nested object. When the returned JsonObject goes out of scope (per syntactic scope or an explicit call to end()), the nested object is closed, and application code can continue adding elements to the owning self object.

Source

pub fn start_array<'c, 'x>( &'x mut self, key: &str, ) -> Result<JsonArray<'c, 'b, W, F, FF>, W::Error>
where 'a: 'c, 'x: 'c,

Start a nested array under a given key. This function returns a new JsonArray instance for writing elements to the nested object. When the returned JsonArray goes out of scope (per syntactic scope or an explicit call to end()), the nested array is closed, and application code can continue adding elements to the owning self object.

Source

pub fn end(self) -> Result<(), W::Error>

Explicitly end this object’s lifetime and write the closing bracket.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_i8_value(&mut self, key: &str, value: i8) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_u8_value(&mut self, key: &str, value: u8) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_i16_value(&mut self, key: &str, value: i16) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_u16_value(&mut self, key: &str, value: u16) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_i32_value(&mut self, key: &str, value: i32) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_u32_value(&mut self, key: &str, value: u32) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_i64_value(&mut self, key: &str, value: i64) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_u64_value(&mut self, key: &str, value: u64) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_i128_value( &mut self, key: &str, value: i128, ) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_u128_value( &mut self, key: &str, value: u128, ) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_isize_value( &mut self, key: &str, value: isize, ) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonObject<'a, 'b, W, F, FF>

Source

pub fn write_usize_value( &mut self, key: &str, value: usize, ) -> Result<(), W::Error>

Write a key/value pair with an int value of type $t.

Trait Implementations§

Source§

impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> Drop for JsonObject<'a, 'b, W, F, FF>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, 'b, W, F, FF> Freeze for JsonObject<'a, 'b, W, F, FF>

§

impl<'a, 'b, W, F, FF> RefUnwindSafe for JsonObject<'a, 'b, W, F, FF>

§

impl<'a, 'b, W, F, FF> Send for JsonObject<'a, 'b, W, F, FF>
where F: Send, FF: Send, W: Send, <W as BlockingWrite>::Error: Send,

§

impl<'a, 'b, W, F, FF> Sync for JsonObject<'a, 'b, W, F, FF>
where F: Sync, FF: Sync, W: Sync, <W as BlockingWrite>::Error: Sync,

§

impl<'a, 'b, W, F, FF> Unpin for JsonObject<'a, 'b, W, F, FF>

§

impl<'a, 'b, W, F, FF> !UnwindSafe for JsonObject<'a, 'b, W, F, FF>

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 = Infallible

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.