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>
impl<'a> ListBuilder<'a>
Sourcepub fn append_int(&mut self, value: i64)
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);Sourcepub fn append_string(&mut self, value: impl AsRef<str>)
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");Sourcepub fn append_bool(&mut self, value: bool)
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); Sourcepub fn append_list(&mut self) -> ListBuilder<'_>
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);Sourcepub fn append_object(&mut self) -> ObjectBuilder<'_>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more