Struct sise::Builder

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

Returns the index path of the last inserted node.

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());

Adds node into the current list.

Creates a new list, pushing the current one into a stack. This new list will be pushed into the current one.

Finishes the current list, popping a list from the stack and setting it as current.

Finishes the builder, making sure that the stack depth is the same as when it was created.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.