Module earth::html [] [src]

The adatper to display a given value as an HTML element.

Example

use earth::feed::Link;
use earth::html::{ForHtml, ToHtml};
let link = Link::new("http://earthreader.org/");

assert_eq!(format!("{}", link), "http://earthreader.org/");
assert_eq!(format!("{}", link.to_html()),
           r#"<link rel="alternate" href="http://earthreader.org/">"#);

If you want to convert the type of values to an HTML element, you can implement std::fmt::Display trait on the type wrapped by this adapter.

use earth::html::{ForHtml, ToHtml};
use std::fmt;

struct Answer(i32);

impl<'a> fmt::Display for ForHtml<'a, Answer> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "<em>{}</em>", self.0)
    }
}
 
assert_eq!(format!("{}", Answer(42).to_html()), "<em>42</em>");

This pattern was suggested from rust-lang/rfcs#565.

Structs

ForHtml

Traits

ToHtml