Skip to main content

join_display

Function join_display 

pub fn join_display<I, S>(iter: I, sep: S) -> impl IntoHtml
where I: IntoIterator, <I as IntoIterator>::Item: Display, S: AsRef<str>,
Available on crate features html and http only.
Expand description

Render the items of iter into HTML, separated by sep.

Each item is rendered through its Display impl and HTML-escaped, so the element type only needs Display — it does not need to implement IntoHtml. The separator is written verbatim: it is treated as trusted, developer-provided structure, exactly like the static parts of a template (so the data is escaped, the structure is not).

This is the idiomatic way to build a CSV-style attribute value (or body) straight from an iterator, instead of pre-joining into a String:

use rama_http::protocols::html::*;

// any `Display` iterator works; here: a list of language tags
let langs = ["en", "fr", "de"];
let tag = meta!("http-equiv" = "Content-Language", content = join_display(langs, ", "));
assert_eq!(
    tag.into_string(),
    r#"<meta http-equiv="Content-Language" content="en, fr, de">"#,
);