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

Style that breaks list in lines and indents them.

Example

use sise::sise_expr;

let tree = sise_expr!(["example", ["1", "2", "3"], ["a", "b", "c"]]);

let spacing_config = sise::SerializeSpacingConfig {
    line_ending: sise::SerializeLineEnding::Lf,
    indent_len: 4,
    indent_char: sise::SerializeIndentChar::Space,
};
let mut keep_same_line = std::collections::HashSet::new();
keep_same_line.insert(tree.index_path(&[1, 1]).unwrap().ref_as_usize());
keep_same_line.insert(tree.index_path(&[1, 2]).unwrap().ref_as_usize());
keep_same_line.insert(tree.index_path(&[2, 1]).unwrap().ref_as_usize());
keep_same_line.insert(tree.index_path(&[2, 2]).unwrap().ref_as_usize());
let spaced = sise::serialize(&tree, &mut sise::SpacedSerializeStyle::new(spacing_config, keep_same_line));
assert_eq!(spaced, "(example\n    (1 2 3)\n    (a b c)\n)\n");

Example with ‘sise::Builder’

let mut builder_base = sise::BuilderBase::new();
let mut builder = builder_base.builder();

let mut keep_same_line_paths = Vec::new();

builder.add_node("example");
builder.begin_list();
builder.add_node("1");
builder.add_node("2");
keep_same_line_paths.push(builder.last_index_path());
builder.add_node("3");
keep_same_line_paths.push(builder.last_index_path());
builder.end_list();
builder.begin_list();
builder.add_node("a");
builder.add_node("b");
keep_same_line_paths.push(builder.last_index_path());
builder.add_node("c");
keep_same_line_paths.push(builder.last_index_path());
builder.end_list();
builder.finish();
let tree = builder_base.into_node();

let spacing_config = sise::SerializeSpacingConfig {
    line_ending: sise::SerializeLineEnding::Lf,
    indent_len: 4,
    indent_char: sise::SerializeIndentChar::Space,
};
let mut keep_same_line = std::collections::HashSet::new();
for keep_same_line_path in keep_same_line_paths {
    keep_same_line.insert(tree.index_path(&keep_same_line_path).unwrap().ref_as_usize());
}
let spaced = sise::serialize(&tree, &mut sise::SpacedSerializeStyle::new(spacing_config, keep_same_line));
assert_eq!(spaced, "(example\n    (1 2 3)\n    (a b c)\n)\n");

Implementations§

Trait Implementations§

Formats the value using the given formatter. Read more
Called at the beginning of the serialization (nothing has been writen to output yet). Read more
Called at the beginning of a list (before writing ( to output)
Called at the end of a list (before writing ) to output)
Called before writing an atom to output.
Called at the end of the serialization (nothing more will be writen to output). Read more

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.