Skip to main content

join_with_spaces

Function join_with_spaces 

Source
pub fn join_with_spaces(layouts: Vec<Box<Layout>>) -> Box<Layout>
Expand description

Joins a collection of layouts with space separators.

This convenience function takes a vector of layouts and combines them with single spaces between each element. It’s equivalent to join_with(layouts, space()) and is commonly used for word-like elements or horizontal layout composition.

§Parameters

  • layouts - Vector of layouts to join with spaces

§Returns

A single layout with all input layouts separated by spaces, or null if empty.

§Examples

use typeset::*;

// Join words with spaces
let sentence = join_with_spaces(vec![
    text_str("Hello"),
    text_str("beautiful"),
    text_str("world")
]);

assert_eq!(format_layout(sentence, 2, 80), "Hello beautiful world");
use typeset::*;

// Join different types of layouts
let mixed = join_with_spaces(vec![
    text_str("fn"),
    text_str("main()"),
    braces(text_str("println!(\"Hello\");"))
]);

// When it fits: "fn main() {println!(\"Hello\");}"
// When it breaks, the braces content may break internally
use typeset::*;

// Empty vector returns null
let empty = join_with_spaces(vec![]);
assert_eq!(format_layout(empty, 2, 80), "");

// Single element returns itself
let single = join_with_spaces(vec![text_str("alone")]);
assert_eq!(format_layout(single, 2, 80), "alone");

§See Also