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

source

pub fn new() -> Self

Creates a new builder instance.

source

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.

source

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.

source

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.

source

pub fn build_object(&self, obj: ObjectBuilder<'_>) -> Doc

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

source

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

source§

fn default() -> DocBuilder

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more