1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! 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.
//!
//! ```ignore
//! 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][].
//!
//! [rust-lang/rfcs#565]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md#user-facing-fmtdisplay
use Deref;
use fmt;