ListBuilder

Struct ListBuilder 

Source
pub struct ListBuilder<'a> { /* private fields */ }
Expand description

Builds an inner list within a Doc or another element.

A builder can either be obtained via DocBuilder::root_list_builder or using either ObjectBuilder::put_list - to place an inner list in another or via ListBuilder::append_list to add a list as child element to a list.

Implementations§

Source§

impl<'a> ListBuilder<'a>

Source

pub fn append_int(&mut self, value: i64)

Appends an integer value to the list being built.

§Example
let mut builder = DocBuilder::new();
let mut list_builder = builder.root_list_builder();

list_builder.append_int(42);

let doc = builder.build();
assert_eq!(doc.root().at(0).as_int().unwrap(), 42);
Source

pub fn append_string(&mut self, value: impl AsRef<str>)

Appends a string to the list being built.

§Example
let mut builder = DocBuilder::new();
let mut list_builder = builder.root_list_builder();

list_builder.append_string("Test");

let doc = builder.build();
assert_eq!(doc.root().at(0).as_str().unwrap(), "Test");
Source

pub fn append_bool(&mut self, value: bool)

Appends a bool value to the list being built.

§Example
let mut builder = DocBuilder::new();
let mut list_builder = builder.root_list_builder();

list_builder.append_bool(true);

let doc = builder.build();
assert_eq!(doc.root().at(0).as_bool(), true);    
Source

pub fn append_list(&mut self) -> ListBuilder<'_>

Appends a child-list to the list being built. Returns the builder used to populate the list.

Note that this will not join two lists but rather construct a list as child element and append further items to this child list.

§Example
let mut builder = DocBuilder::new();
let mut list_builder = builder.root_list_builder();

let mut child_list_builder = list_builder.append_list();
child_list_builder.append_int(42);

let doc = builder.build();
assert_eq!(doc.root().len(), 1);    
assert_eq!(doc.root().at(0).len(), 1);    
assert_eq!(doc.root().at(0).at(0).as_int().unwrap(), 42);
Source

pub fn append_object(&mut self) -> ObjectBuilder<'_>

Appends a child object to the list being built. Returns the builder used to populate the object.

§Example
let mut builder = DocBuilder::new();
let mut list_builder = builder.root_list_builder();

let mut obj_builder = list_builder.append_object();
obj_builder.put_string("Foo", "Bar").unwrap();

let doc = builder.build();
assert_eq!(doc.root().len(), 1);    
assert_eq!(doc.root().at(0).query("Foo").as_str().unwrap(), "Bar");

Auto Trait Implementations§

§

impl<'a> Freeze for ListBuilder<'a>

§

impl<'a> RefUnwindSafe for ListBuilder<'a>

§

impl<'a> Send for ListBuilder<'a>

§

impl<'a> Sync for ListBuilder<'a>

§

impl<'a> Unpin for ListBuilder<'a>

§

impl<'a> !UnwindSafe for ListBuilder<'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 = 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.