Skip to main content

nest

Function nest 

Source
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 tab parameter in rendering
  • Nesting levels accumulate - nested nest calls create deeper indentation
  • Single-line content is not affected

§See Also

  • pack - For alignment-based indentation instead of fixed-width
  • [format_layout] - The tab parameter controls indentation width
  • [braces], [parens] - Often combined with nest for block structures