#html #scope #write #stdout #allocation #id #wrap-io

write_scope_html

A write_scope front-end for HTML

1 unstable release

new 0.1.0 Apr 22, 2025

#38 in #stdout

Download history 83/week @ 2025-04-20

83 downloads per month

MIT license

15KB
349 lines

A [write_scope] library for HTML

Example

fn main() -> io::Result<()> {
    let w = WrapIO(stdout().lock());
    let html = w.open(Html)?;
    let mut body = html.open(Body)?;
    {
        let id = String::from("toto");
        let mut toto = body.ref_open(Div.id(&id).id("babar"))?.open(Div)?;
        drop(id);
        toto.ref_open(Div.id("toto_1"))?;
        toto.ref_open(Div.id("toto_2"))?;
        toto.close()?;
    }
    body.ref_open(Div.id("tata"))?;
    body.open_scope(Div.id("tutu"), |tutu| {
        tutu.open(H1)?.text("Hello!")?;
        tutu.open(P)?.text("Beautiful morning!")?;
        Ok(())
    })?;
    body.open(Div)?;
    Ok(())
}

Dependencies