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.
Trait Implementations§
source§impl Default for DocBuilder
impl Default for DocBuilder
source§fn default() -> DocBuilder
fn default() -> DocBuilder
Auto Trait Implementations§
impl !Freeze for DocBuilder
impl RefUnwindSafe for DocBuilder
impl Send for DocBuilder
impl Sync for DocBuilder
impl Unpin for DocBuilder
impl UnwindSafe for DocBuilder
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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more