pub fn join_with_commas(layouts: Vec<Box<Layout>>) -> Box<Layout>Expand description
Joins a collection of layouts with comma separators.
This convenience function takes a vector of layouts and combines them with
comma-space separators (“, “) between each element. It’s equivalent to
join_with(layouts, comma()) but note that the underlying implementation
adds both comma and space. This is the standard way to create comma-separated
lists like function parameters, array elements, or object properties.
§Parameters
layouts- Vector of layouts to join with commas
§Returns
A single layout with all input layouts separated by “, “, or null if empty.
§Examples
use typeset::*;
// Function parameter list
let params = join_with_commas(vec![
text_str("x: i32"),
text_str("y: i32"),
text_str("z: String")
]);
let function = comp(
text_str("fn example("),
comp(params, text_str(")"), false, false),
false, false
);
// Output: "fn example(x: i32, y: i32, z: String)"use typeset::*;
// Array elements that may break
let array = brackets(
grp(join_with_commas(vec![
text_str("element1"),
text_str("element2"),
text_str("element3")
]))
);
// Fits: "[element1, element2, element3]"
// Breaks: "[element1,
// element2,
// element3]"use typeset::*;
// JSON-like object properties
let object = braces(
nest(join_with_commas(vec![
comp(text_str("\"name\""), text_str(": \"John\""), true, false),
comp(text_str("\"age\""), text_str(": 30"), true, false)
]))
);§See Also
join_with_spaces- For space-separated elementsjoin_with- Generic joining with any separatorcomma- The separator character used- [
grp] - Often used to control breaking behavior of comma-separated lists