pub struct JsonArray<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> { /* private fields */ }Expand description
A JsonArray is the API for writing a JSON array, i.e. a sequence of elements. The
closing ] is written when the JsonArray 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 JsonArray instance.
Implementations§
Source§impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonArray<'a, 'b, W, F, FF>
impl<'a, 'b, W: BlockingWrite, F: JsonFormatter, FF: FloatFormat> JsonArray<'a, 'b, W, F, FF>
Sourcepub fn new(writer: &'a mut JsonWriter<'b, W, F, FF>) -> Result<Self, W::Error>
pub fn new(writer: &'a mut JsonWriter<'b, W, F, FF>) -> Result<Self, W::Error>
Create a new JsonArray instance. Application code can do this explicitly only initially as a starting point for writing JSON. Nested arrays are created by the library.
Sourcepub fn write_string_value(&mut self, value: &str) -> Result<(), W::Error>
pub fn write_string_value(&mut self, value: &str) -> Result<(), W::Error>
Write an element of type ‘string’, escaping the provided string value.
Sourcepub fn write_bool_value(&mut self, value: bool) -> Result<(), W::Error>
pub fn write_bool_value(&mut self, value: bool) -> Result<(), W::Error>
Write an element of type ‘bool’.
Sourcepub fn write_null_value(&mut self) -> Result<(), W::Error>
pub fn write_null_value(&mut self) -> Result<(), W::Error>
Write a null literal as an element.
Sourcepub fn write_f64_value(&mut self, value: f64) -> Result<(), W::Error>
pub fn write_f64_value(&mut self, value: f64) -> Result<(), W::Error>
Write an f64 value as an element. If the value is not finite (i.e. infinite or NaN), a null literal is written instead. Different behavior (e.g. leaving out the element for non-finite numbers, representing them in some other way etc.) is the responsibility of application code.
Sourcepub fn write_f32_value(&mut self, value: f32) -> Result<(), W::Error>
pub fn write_f32_value(&mut self, value: f32) -> Result<(), W::Error>
Write an f32 value as an element. If the value is not finite (i.e. infinite or NaN), a null literal is written instead. Different behavior (e.g. leaving out the element for non-finite numbers, representing them in some other way etc.) is the responsibility of application code.
Sourcepub fn start_object<'c, 'x>(
&'x mut self,
) -> Result<JsonObject<'c, 'b, W, F, FF>, W::Error>where
'a: 'c,
'x: 'c,
pub fn start_object<'c, 'x>(
&'x mut self,
) -> Result<JsonObject<'c, 'b, W, F, FF>, W::Error>where
'a: 'c,
'x: 'c,
Start a nested object as an element. 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.
Sourcepub fn start_array<'c, 'x>(
&'x mut self,
) -> Result<JsonArray<'c, 'b, W, F, FF>, W::Error>where
'a: 'c,
'x: 'c,
pub fn start_array<'c, 'x>(
&'x mut self,
) -> Result<JsonArray<'c, 'b, W, F, FF>, W::Error>where
'a: 'c,
'x: 'c,
Start a nested array as an element. 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 object is closed, and
application code can continue adding elements to the owning self object.