Struct jupiter::ig::builder::ObjectBuilder
source · pub struct ObjectBuilder<'a> { /* private fields */ }
Expand description
Builds an inner object or map within a Doc
or another element.
A builder can either be obtained via DocBuilder::build_object.
Implementations§
source§impl<'a> ObjectBuilder<'a>
impl<'a> ObjectBuilder<'a>
sourcepub fn put_int(&mut self, key: impl AsRef<str>, value: i64) -> Result<()>
pub fn put_int(&mut self, key: impl AsRef<str>, value: i64) -> Result<()>
Places an integer value within the object being built.
§Errors
If the internal symbol table overflows, an error is returned.
§Example
let mut builder = DocBuilder::new();
let mut obj_builder = builder.obj();
obj_builder.put_int("Test", 42).unwrap();
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").as_int().unwrap(), 42);
sourcepub fn insert_int(&mut self, key: Symbol, value: i64)
pub fn insert_int(&mut self, key: Symbol, value: i64)
Places an integer value within the object being built using a Symbol
which has been looked
up previously.
§Example
let mut builder = DocBuilder::new();
let key = builder.resolve("Test").unwrap();
let mut obj_builder = builder.obj();
obj_builder.insert_int(key, 42);
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").as_int().unwrap(), 42);
sourcepub fn put_string(
&mut self,
key: impl AsRef<str>,
value: impl AsRef<str>
) -> Result<()>
pub fn put_string( &mut self, key: impl AsRef<str>, value: impl AsRef<str> ) -> Result<()>
Places a string value within the object being built.
§Errors
If the internal symbol table overflows, an error is returned.
§Example
let builder = DocBuilder::new();
let mut obj_builder = builder.obj();
obj_builder.put_string("Test", "Foo").unwrap();
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").as_str().unwrap(), "Foo");
sourcepub fn insert_string(&mut self, key: Symbol, value: impl AsRef<str>)
pub fn insert_string(&mut self, key: Symbol, value: impl AsRef<str>)
Places a string value within the object being built using a Symbol
which has been looked
up previously.
§Example
let builder = DocBuilder::new();
let key = builder.resolve("Test").unwrap();
let mut obj_builder = builder.obj();
obj_builder.insert_string(key, "Foo");
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").as_str().unwrap(), "Foo");
sourcepub fn put_bool(&mut self, key: impl AsRef<str>, value: bool) -> Result<()>
pub fn put_bool(&mut self, key: impl AsRef<str>, value: bool) -> Result<()>
Places a bool value within the object being built.
§Errors
If the internal symbol table overflows, an error is returned.
§Example
let builder = DocBuilder::new();
let mut obj_builder = builder.obj();
obj_builder.put_bool("Test", true).unwrap();
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").as_bool(), true);
sourcepub fn insert_bool(&mut self, key: Symbol, value: bool)
pub fn insert_bool(&mut self, key: Symbol, value: bool)
Places bool value within the object being built using a Symbol
which has been looked
up previously.
§Example
let builder = DocBuilder::new();
let key = builder.resolve("Test").unwrap();
let mut obj_builder = builder.obj();
obj_builder.insert_bool(key, true);
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").as_bool(), true);
sourcepub fn put_list(
&mut self,
key: impl AsRef<str>,
list: ListBuilder
) -> Result<()>
pub fn put_list( &mut self, key: impl AsRef<str>, list: ListBuilder ) -> Result<()>
Places a list value within the object being built. Returns the builder used to populate the list.
§Errors
If the internal symbol table overflows, an error is returned.
§Example
let builder = DocBuilder::new();
let mut obj_builder = builder.obj();
let mut list_builder = builder.list();
list_builder.append_int(1);
obj_builder.put_list("Test", list_builder).unwrap();
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").at(0).as_int().unwrap(), 1);
sourcepub fn insert_list(&mut self, key: Symbol, list: ListBuilder)
pub fn insert_list(&mut self, key: Symbol, list: ListBuilder)
Places a list value within the object being built using a Symbol
which has been looked
up previously. Returns the builder used to populate the list.
§Example
let builder = DocBuilder::new();
let key = builder.resolve("Test").unwrap();
let mut obj_builder = builder.obj();
let mut list_builder = builder.list();
list_builder.append_int(1);
obj_builder.insert_list(key, list_builder);
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test").at(0).as_int().unwrap(), 1);
sourcepub fn put_object(
&mut self,
key: impl AsRef<str>,
obj: ObjectBuilder<'_>
) -> Result<()>
pub fn put_object( &mut self, key: impl AsRef<str>, obj: ObjectBuilder<'_> ) -> Result<()>
Places an inner object within the object being built. Returns the builder used to populate the list.
§Errors
If the internal symbol table overflows, an error is returned.
§Example
let builder = DocBuilder::new();
let mut obj_builder = builder.obj();
let mut inner_obj_builder = builder.obj();
inner_obj_builder.put_string("Foo", "Bar").unwrap();
obj_builder.put_object("Test", inner_obj_builder).unwrap();
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test.Foo").as_str().unwrap(), "Bar");
sourcepub fn insert_object(&mut self, key: Symbol, obj: ObjectBuilder<'_>)
pub fn insert_object(&mut self, key: Symbol, obj: ObjectBuilder<'_>)
Places an inner object within the object being built using a Symbol
which has been looked
up previously. Returns the builder used to populate the list.
§Example
let builder = DocBuilder::new();
let key = builder.resolve("Test").unwrap();
let mut obj_builder = builder.obj();
let mut inner_obj_builder = builder.obj();
inner_obj_builder.put_string("Foo", "Bar").unwrap();
obj_builder.insert_object(key, inner_obj_builder);
let doc = builder.build_object(obj_builder);
assert_eq!(doc.root().query("Test.Foo").as_str().unwrap(), "Bar");
Auto Trait Implementations§
impl<'a> Freeze for ObjectBuilder<'a>
impl<'a> RefUnwindSafe for ObjectBuilder<'a>
impl<'a> Send for ObjectBuilder<'a>
impl<'a> Sync for ObjectBuilder<'a>
impl<'a> Unpin for ObjectBuilder<'a>
impl<'a> UnwindSafe for ObjectBuilder<'a>
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