Function parens

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

Wraps a layout in parentheses.

This convenience function surrounds the given layout with parentheses, using unpadded compositions to ensure no extra spaces are added between the parentheses and the content. This is commonly used for function calls, mathematical expressions, grouping operations, and similar constructs.

§Parameters

  • layout - The layout to wrap in parentheses

§Returns

A layout wrapped in parentheses: (content)

§Examples

use typeset::*;

// Function call
let call = comp(
    text_str("function"),
    parens(join_with_commas(vec![
        text_str("arg1"),
        text_str("arg2")
    ])),
    false, false
);

assert_eq!(format_layout(call, 2, 80), "function(arg1, arg2)");
use typeset::*;

// Mathematical expression grouping
let expr = comp(
    text_str("a +"),
    parens(comp(
        text_str("b * c"),
        text_str(""),
        true, false
    )),
    true, false
);

// Output: "a + (b * c)"
use typeset::*;

// Nested parentheses
let nested = parens(
    parens(text_str("inner"))
);

assert_eq!(format_layout(nested, 2, 80), "((inner))");

§Behavior

  • Uses unpadded compositions (pad=false) to avoid spaces around parentheses
  • The wrapped content can break internally based on its own structure
  • Parentheses themselves never break apart from their content
  • No additional spacing is introduced

§See Also

  • brackets - For wrapping in square brackets []
  • braces - For wrapping in curly braces {}
  • comp - The underlying composition constructor used