/// Renders the configuration for human display, as a short HTML description.
pub(crate) fn render_short_html(&self) -> String {
- let mut msg = Html(self).to_string();
+ let mut msg = ShortHtml(self).to_string();
if self.should_capitalize_first_letter() {
if let Some(i) = msg.find(|c: char| c.is_ascii_alphanumeric()) {
msg[i .. i+1].make_ascii_uppercase();
/// Renders the configuration for long display, as a long HTML description.
pub(crate) fn render_long_html(&self) -> String {
- let mut msg = format!("This is supported on <strong>{}</strong>", Html(self));
+ let on = if self.should_use_with_in_description() {
+ "with"
+ } else {
+ "on"
+ };
+
+ let mut msg = format!("This is supported {} <strong>{}</strong>", on, Html(self));
if self.should_append_only_to_description() {
msg.push_str(" only");
}
}
}
}
+
+ fn should_use_with_in_description(&self) -> bool {
+ match *self {
+ Cfg::Cfg(ref name, _) if name == &"target_feature" => true,
+ _ => false,
+ }
+ }
}
impl ops::Not for Cfg {
},
("target_endian", Some(endian)) => return write!(fmt, "{}-endian", endian),
("target_pointer_width", Some(bits)) => return write!(fmt, "{}-bit", bits),
+ ("target_feature", Some(feat)) =>
+ return write!(fmt, "target feature <code>{}</code>", feat),
_ => "",
};
if !human_readable.is_empty() {
}
}
+struct ShortHtml<'a>(&'a Cfg);
+
+impl<'a> fmt::Display for ShortHtml<'a> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ match *self.0 {
+ Cfg::Cfg(ref name, Some(ref vendor)) if name == &"target_feature" => {
+ write!(fmt, "<code>{}</code>", vendor)
+ },
+ ref cfg => write!(fmt, "{}", Html(cfg)),
+ }
+ }
+}
+
#[cfg(test)]
mod test {
use super::Cfg;
).render_short_html(),
"(Debug-assertions enabled or Windows) and Unix"
);
+ assert_eq!(
+ name_value_cfg("target_feature", "sse2").render_short_html(),
+ "<code>sse2</code>"
+ );
})
}
"This is supported on <strong>(debug-assertions enabled or Windows) and Unix\
</strong> only."
);
+ assert_eq!(
+ name_value_cfg("target_feature", "sse2").render_long_html(),
+ "This is supported with <strong>target feature <code>sse2</code></strong> only."
+ );
})
}
}