pub struct Builder<'a> { /* private fields */ }
Expand description
Helper struct to build SISE trees and get index paths of the inserted nodes.
Example
use sise::sise_expr;
let mut builder_base = sise::BuilderBase::new();
let mut builder = builder_base.builder();
// Build (atom-1 atom-2 (atom-3 atom-4) atom-5)
builder.add_node("atom-1");
assert_eq!(builder.last_index_path(), [0]);
builder.add_node("atom-2");
assert_eq!(builder.last_index_path(), [1]);
builder.begin_list();
builder.add_node("atom-3");
assert_eq!(builder.last_index_path(), [2, 0]);
builder.add_node("atom-4");
assert_eq!(builder.last_index_path(), [2, 1]);
builder.end_list();
assert_eq!(builder.last_index_path(), [2]);
builder.add_node("atom-5");
assert_eq!(builder.last_index_path(), [3]);
builder.finish();
let root_node = builder_base.into_node();
let expected = sise_expr!(["atom-1", "atom-2", ["atom-3", "atom-4"], "atom-5"]);
assert_eq!(root_node, expected);
Implementations§
source§impl<'a> Builder<'a>
impl<'a> Builder<'a>
sourcepub fn last_index_path(&self) -> Vec<usize>
pub fn last_index_path(&self) -> Vec<usize>
Returns the index path of the last inserted node.
sourcepub fn sub_builder<'b>(&'b mut self) -> Builder<'b>
pub fn sub_builder<'b>(&'b mut self) -> Builder<'b>
Creates a builder that won’t allow to pop further.
Example
let r = std::panic::catch_unwind(|| {
let mut builder_base = sise::BuilderBase::new();
let mut builder = builder_base.builder();
builder.begin_list();
let mut builder2 = builder.sub_builder();
builder2.end_list();
});
assert!(r.is_err());
sourcepub fn begin_list(&mut self)
pub fn begin_list(&mut self)
Creates a new list, pushing the current one into a stack. This new list will be pushed into the current one.