Skip to main content

line

Function line 

Source
pub fn line(left: Box<Layout>, right: Box<Layout>) -> Box<Layout>
Expand description

Creates a forced line break between two layouts.

The line constructor places its left layout on one line and its right layout on the next line, with appropriate indentation. This creates an unconditional line break, unlike compositions which may or may not break depending on available width.

§Parameters

  • left - Layout to appear before the line break
  • right - Layout to appear after the line break (on the next line)

§Returns

A boxed Layout::Line that forces a line break between the layouts.

§Examples

use typeset::*;

// Simple line break
let two_lines = line(
    text_str("First line"),
    text_str("Second line")
);

assert_eq!(format_layout(two_lines, 2, 80), "First line\nSecond line");
use typeset::*;

// Build multi-line structures
let code_block = line(
    text_str("if condition {"),
    line(
        nest(text_str("do_something();")),
        text_str("}")
    )
);

// Output:
// if condition {
//   do_something();
// }

§Behavior

  • Always creates a line break, regardless of available width
  • Respects current indentation level for the right layout
  • Can be chained to create multiple line breaks
  • The right layout inherits the current nesting context

§See Also

  • [newline] - Convenience function for line breaks with empty content
  • [blank_line] - Creates double line breaks
  • [join_with_lines] - Joins multiple layouts with line breaks
  • comp - For conditional breaking based on width