Skip to main content

fix_pad

Function fix_pad 

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

Creates a fixed, padded composition between two layouts.

This convenience function creates a composition with both padding and fixing enabled. The layouts are always placed on the same line with a space between them, regardless of width constraints. This is equivalent to comp(left, right, true, true) and is useful for constructs that must never be broken apart.

§Parameters

  • left - The left layout in the composition
  • right - The right layout in the composition

§Returns

A fixed, padded composition that never breaks.

§Examples

use typeset::*;

// Keyword-identifier pairs that should stay together
let declaration = fix_pad(
    text_str("let"),
    text_str("variable")
);

// Always renders as: "let variable"
// Even in very narrow widths, this won't break
use typeset::*;

// Operators that should stay with their operands
let operation = fix_pad(
    text_str("!"),
    text_str("condition")
);

assert_eq!(format_layout(operation, 2, 5), "! condition");
// Note: This will exceed the width limit of 5 but won't break
use typeset::*;

// Type annotations
let typed = comp(
    text_str("value:"),
    fix_pad(text_str("&"), text_str("str")),
    true, false
);

// The "& str" part always stays together

§Behavior

  • Padding: true - Always adds a space between layouts
  • Fixing: true - Never breaks, regardless of width constraints
  • Use with caution - can cause lines to exceed width limits
  • Overrides all breaking decisions for this composition
  • The space is always present, never replaced by a line break

§Use Cases

  • Keyword-identifier pairs (“let x”, “fn name”)
  • Type annotations (“&str”, “Vec<T>”)
  • Operators with operands (“!flag”, “*ptr”)
  • Short phrases that lose meaning when broken

§See Also

  • pad - Padded composition that can break
  • fix_unpad - Fixed composition without spaces
  • [fix] - Alternative way to prevent breaking
  • comp - The underlying composition function