pub fn nest(layout: Box<Layout>) -> Box<Layout>Expand description
Wraps a layout to add fixed-width indentation.
The nest constructor adds indentation to its wrapped content when that
content spans multiple lines. The indentation width is determined by the
tab parameter passed to the rendering function. This is the standard
way to create nested, hierarchical layouts.
§Parameters
layout- The layout to indent when it breaks across lines
§Returns
A boxed Layout::Nest that adds indentation to broken content.
§Examples
use typeset::*;
// Create a nested block structure
let block = braces(
nest(join_with_lines(vec![
text_str("statement1;"),
text_str("statement2;"),
text_str("statement3;")
]))
);
let result = format_layout(block, 2, 15); // 2-space indentation, narrow width
// Output:
// {
// statement1;
// statement2;
// statement3;
// }use typeset::*;
// Nest function parameters
let func = comp(
text_str("function("),
comp(
nest(join_with_commas(vec![
text_str("param1: Type1"),
text_str("param2: Type2")
])),
text_str(")"),
false, false
),
false, false
);§Behavior
- Indentation only applies when content breaks across multiple lines
- The indentation amount is controlled by the
tabparameter in rendering - Nesting levels accumulate - nested
nestcalls create deeper indentation - Single-line content is not affected
§See Also
pack- For alignment-based indentation instead of fixed-width- [
format_layout] - Thetabparameter controls indentation width - [
braces], [parens] - Often combined with nest for block structures