pub struct DocBuilder { /* private fields */ }Expand description
Provides a builder to generate a Doc.
A doc an internally have either a list or a map as its root node. Therefore either
root_object_builder()or root_list_builder() has to be called the retrieve the
appropriate builder after which build() must be called to create the resulting Doc.
§Examples
Creating a list based Doc:
let mut builder = DocBuilder::new();
let mut list_builder = builder.root_list_builder();
list_builder.append_int(1);
list_builder.append_int(2);
list_builder.append_int(3);
let doc = builder.build();
assert_eq!(doc.root().at(1).as_int().unwrap(), 2);Creating a map based Doc:
let mut builder = DocBuilder::new();
let mut obj_builder = builder.root_object_builder();
obj_builder.put_int("Test", 1);
obj_builder.put_int("Foo", 2);
let doc = builder.build();
assert_eq!(doc.root().query("Test").as_int().unwrap(), 1);
assert_eq!(doc.root().query("Foo").as_int().unwrap(), 2);Implementations§
Source§impl DocBuilder
impl DocBuilder
Sourcepub fn resolve(&mut self, symbol: impl AsRef<str>) -> Result<Symbol>
pub fn resolve(&mut self, symbol: impl AsRef<str>) -> Result<Symbol>
Resolves the given name into a Symbol for repeated insertions.
§Errors
If the internal symbol table overflows, an error is returned.
Sourcepub fn root_object_builder(&mut self) -> ObjectBuilder<'_>
pub fn root_object_builder(&mut self) -> ObjectBuilder<'_>
Makes the root node of the Doc a map and returns a builder for it.
Note that for each DocBuilder either root_object_builder or root_list_builder
has to called exactly once.
Sourcepub fn root_list_builder(&mut self) -> ListBuilder<'_>
pub fn root_list_builder(&mut self) -> ListBuilder<'_>
Makes the root node of the Doc a list and returns a builder for it.
Note that for each DocBuilder either root_object_builder or root_list_builder
has to called exactly once.