Crate tagger[][src]

This crate provides primitives to build up a html/xml/svg document programatically. Instead of using a templating engine, write data/markup that ‘looks like’ rust.

Why so many closures?

Unlike Drop, passing closures can be used to force the user to handle errors when something goes out of scope. If we put the writing of end tags in a Drop method it could silently fail, which is not ideal. This can be worked around by adding an explicit function to write the end tag, but there is no way to guarantee that this function gets called at compile time. The best you can do is a runtime panic if the finalizer function isn’t called in order to handle the error case. With closures, you can force a compile-time error.

Examples

See it in use in the poloto crate. Also check out the examples at github.

Modules

prelude

The prelude to import the element manipulation convenience macros.

svg

svg related building blocks

tag_types

Common tags to be used in Element::single_ext

Macros

wr

Convenience macro to reduce code. Shorthand for ’move |w|write!(w,…)` Create a closure that will use write!() with the formatting arguments.

write_ret

Just like the regular write! macro except it returns itself upon success.

Structs

AttributeWriter

Builder to write out attributes to an element.

Element

An element.

ElementHeaderWriter

Used by Element::elem

WriterAdaptor

Used by upgrade

Traits

WriteAttr

Functions the user can call to add attributes. AttributeWriter could have implemented these, but lets use a trait to simplify lifetimes.

Functions

upgrade

Upgrade a std::io::Write to be a std::fmt::Write

write_fmt_ret

fmt::Write::write_fmt doesn’t return itself on success. This version does.