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§

Creates a new builder instance.

Resolves the given name into a Symbol for repeated insertions.

Errors

If the internal symbol table overflows, an error is returned.

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.

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.

Turns the builder into a Doc which root element is an object.

Turns the builder into a Doc which root element is a list.

Trait Implementations§

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more