pub struct SequenceBuilder { /* private fields */ }
Expand description

Constructs Sequence, List, and SExp values incrementally.

Building a Sequence:

use ion_rs::element::{Element, Sequence};
let actual: Sequence = Sequence::builder().push(1).push(true).push("foo").build();
let expected: Sequence = Sequence::new([
    Element::integer(1),
    Element::boolean(true),
    Element::string("foo"),
]);
assert_eq!(actual, expected);

Building a List:

use ion_rs::element::{Element, List, Sequence};
let actual: List = Sequence::builder()
    .push(1)
    .push(true)
    .push("foo")
    .build_list();
let expected: List = List(Sequence::new([
    Element::integer(1),
    Element::boolean(true),
    Element::string("foo"),
]));
assert_eq!(actual, expected);

Building a SExp:

use ion_rs::element::{Element, SExp, Sequence};
let actual: SExp = Sequence::builder()
    .push(1)
    .push(true)
    .push("foo")
    .build_sexp();
let expected: SExp = SExp(Sequence::new([
    Element::integer(1),
    Element::boolean(true),
    Element::string("foo"),
]));
assert_eq!(actual, expected);

Implementations§

source§

impl SequenceBuilder

source

pub fn push<E: Into<Element>>(self, element: E) -> Self

Adds the provided element to the end of the Sequence being constructed.

source

pub fn remove(self, index: usize) -> Self

Removes the element at the specified position from the Sequence being constructed. If the index is out of bounds, this method will panic.

source

pub fn build(self) -> Sequence

Builds a Sequence with the previously specified elements.

source

pub fn build_list(self) -> List

Builds a List with the previously specified elements.

source

pub fn build_sexp(self) -> SExp

Builds a SExp with the previously specified elements.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.