DocBuilder

Struct 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 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

Source

pub fn new() -> Self

Creates a new builder instance.

Source

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.

Source

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.

Source

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.

Source

pub fn build(self) -> Doc

Turns the builder into a Doc.

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.