Struct jupiter::ig::builder::DocBuilder
source · 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
build_object()or build_list() has to be called to create the resulting Doc.
Examples
Creating a list based Doc:
let builder = DocBuilder::new();
let mut list_builder = builder.list();
list_builder.append_int(1);
list_builder.append_int(2);
list_builder.append_int(3);
let doc = builder.build_list(list_builder);
assert_eq!(doc.root().at(1).as_int().unwrap(), 2);Creating a map based Doc:
let builder = DocBuilder::new();
let mut obj_builder = builder.obj();
obj_builder.put_int("Test", 1);
obj_builder.put_int("Foo", 2);
let doc = builder.build_object(obj_builder);
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(&self, symbol: impl AsRef<str>) -> Result<Symbol>
pub fn resolve(&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 obj(&self) -> ObjectBuilder<'_>
pub fn obj(&self) -> ObjectBuilder<'_>
Creates a new object to be used as either the root object or a child object within the Doc being built.
We need a factory function here, so that we can access the shared symbol table and therefore provide convenience methods like put_string.
sourcepub fn list(&self) -> ListBuilder
pub fn list(&self) -> ListBuilder
Creates a new list to be used as either the root list or a child list within the Doc being built.
Note that technically there is currently no reason to use a factory function here. However, to be future proof and to also be symmetrical to obj(), we still provide this as the default way to obtain a ListBuilder.
sourcepub fn build_object(&self, obj: ObjectBuilder<'_>) -> Doc
pub fn build_object(&self, obj: ObjectBuilder<'_>) -> Doc
Turns the builder into a Doc which root element is an object.
sourcepub fn build_list(&self, list: ListBuilder) -> Doc
pub fn build_list(&self, list: ListBuilder) -> Doc
Turns the builder into a Doc which root element is a list.