//! Small formatting helpers shared across `Display` implementations.

use std::fmt::Display;

/// Join a slice of `Display` values into a `sep`-separated string.
///
/// Replaces the repeated `iter().map(|x| format!("{x}")).collect::<Vec<_>>().join(sep)`
/// dance in the AST and runtime-value `Display` impls. (Callers that format more than the
/// value itself; e.g. `name: type` pairs; keep their bespoke `map` closure.)
pub(crate) fn join_display<T: Display>(items: &[T], sep: &str) -> String {
    items
        .iter()
        .map(ToString::to_string)
        .collect::<Vec<_>>()
        .join(sep)
}
