pub fn join_with_lines(layouts: Vec<Box<Layout>>) -> Box<Layout>Expand description
Joins a collection of layouts with line breaks.
This function combines multiple layouts by placing each on its own line using
line() constructors. Unlike join_with which uses compositions that may
or may not break, this function creates unconditional line breaks between
all elements. It’s ideal for statement sequences, block content, or any
vertically-aligned content.
§Parameters
layouts- Vector of layouts to join with line breaks
§Returns
A single layout with each element on its own line, or null if empty.
§Examples
use typeset::*;
// Statement sequence
let statements = join_with_lines(vec![
text_str("let x = 1;"),
text_str("let y = 2;"),
text_str("println!(\"{}, {}\", x, y);")
]);
let result = format_layout(statements, 2, 80);
// Output:
// let x = 1;
// let y = 2;
// println!("{}, {}", x, y);use typeset::*;
// Block content with nesting
let block = braces(
nest(join_with_lines(vec![
text_str("first_action();"),
text_str("second_action();"),
text_str("return result;")
]))
);
// Output:
// {
// first_action();
// second_action();
// return result;
// }use typeset::*;
// Combine with other constructors
let function = line(
text_str("fn example() {"),
line(
join_with_lines(vec![
nest(text_str("statement1;")),
nest(text_str("statement2;"))
]),
text_str("}")
)
);§Behavior
- Empty vector returns
null - Single element vector returns that element unchanged
- Multiple elements are connected with
line()constructors - Each element appears on its own line with proper indentation
- Line breaks are unconditional (not affected by width constraints)
§Edge Cases
use typeset::*;
// Empty vector
let empty = join_with_lines(vec![]);
assert_eq!(format_layout(empty, 2, 80), "");
// Single element
let single = join_with_lines(vec![text_str("alone")]);
assert_eq!(format_layout(single, 2, 80), "alone");