Skip to main content

pack

Function pack 

Source
pub fn pack(layout: Box<Layout>) -> Box<Layout>
Expand description

Wraps a layout to add alignment-based indentation.

The pack constructor aligns its content to the column position where the first text element appears, rather than using fixed-width indentation like nest. This creates “hanging” indentation that aligns with the start of the content, commonly used for parameter lists and similar structures.

§Parameters

  • layout - The layout to align based on first element position

§Returns

A boxed Layout::Pack that provides alignment-based indentation.

§Examples

use typeset::*;

// Pack aligns to the first element position
let func_call = comp(
    text_str("very_long_function_name("),
    pack(join_with_commas(vec![
        text_str("first_parameter"),
        text_str("second_parameter"),
        text_str("third_parameter")
    ])),
    false, false
);

// When broken, parameters align with the first parameter:
// very_long_function_name(first_parameter,
//                         second_parameter,
//                         third_parameter)
use typeset::*;

// Compare with nest (fixed indentation):
let with_nest = comp(
    text_str("func("),
    nest(text_str("param")),
    false, false
);
// Produces: func(
//             param   (fixed indentation)

let with_pack = comp(
    text_str("func("),
    pack(text_str("param")),
    false, false  
);
// Produces: func(param   (aligns to position after 'func(')

§Behavior

  • Indentation aligns to the column where content starts
  • More flexible than fixed-width nest for varying prefixes
  • Particularly useful for function calls, method chaining, and similar patterns
  • Alignment is based on the first text element encountered

§See Also

  • nest - For fixed-width indentation
  • [join_with_commas] - Often used within pack for parameter lists
  • [comp] - Used to combine prefixes with packed content