1
Fork 0

rustdoc: Only include a stability span if needed.

This commit is contained in:
Jimmy Cuadra 2017-02-11 04:16:13 -08:00
parent bae454edc5
commit c603839d5f
2 changed files with 32 additions and 15 deletions

View file

@ -327,17 +327,27 @@ impl Item {
} }
} }
pub fn stability_class(&self) -> String { pub fn stability_class(&self) -> Option<String> {
self.stability.as_ref().map(|ref s| { match self.stability {
let mut base = match s.level { Some(ref s) => {
stability::Unstable => "unstable".to_string(), let mut classes = Vec::with_capacity(2);
stability::Stable => String::new(),
}; if s.level == stability::Unstable {
if !s.deprecated_since.is_empty() { classes.push("unstable");
base.push_str(" deprecated"); }
if !s.deprecated_since.is_empty() {
classes.push("deprecated");
}
if classes.len() != 0 {
Some(classes.join(" "))
} else {
None
}
}
None => None,
} }
base
}).unwrap_or(String::new())
} }
pub fn stable_since(&self) -> Option<&str> { pub fn stable_since(&self) -> Option<&str> {

View file

@ -1827,7 +1827,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
stab_docs = stab_docs, stab_docs = stab_docs,
docs = shorter(Some(&Markdown(doc_value).to_string())), docs = shorter(Some(&Markdown(doc_value).to_string())),
class = myitem.type_(), class = myitem.type_(),
stab = myitem.stability_class(), stab = myitem.stability_class().unwrap_or("".to_string()),
unsafety_flag = unsafety_flag, unsafety_flag = unsafety_flag,
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()), href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
title = full_path(cx, myitem))?; title = full_path(cx, myitem))?;
@ -2369,13 +2369,16 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "<span id='{id}' class='{item_type}'> write!(w, "<span id='{id}' class='{item_type}'>
<span id='{ns_id}' class='invisible'> <span id='{ns_id}' class='invisible'>
<code>{name}: {ty}</code> <code>{name}: {ty}</code>
</span></span><span class='stab {stab}'></span>", </span></span>",
item_type = ItemType::StructField, item_type = ItemType::StructField,
id = id, id = id,
ns_id = ns_id, ns_id = ns_id,
stab = field.stability_class(),
name = field.name.as_ref().unwrap(), name = field.name.as_ref().unwrap(),
ty = ty)?; ty = ty)?;
if let Some(stability_class) = field.stability_class() {
write!(w, "<span class='stab {stab}'></span>",
stab = stability_class)?;
}
document(w, cx, field)?; document(w, cx, field)?;
} }
} }
@ -2406,11 +2409,15 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "<h2 class='fields'>Fields</h2>")?; write!(w, "<h2 class='fields'>Fields</h2>")?;
for (field, ty) in fields { for (field, ty) in fields {
write!(w, "<span id='{shortty}.{name}' class='{shortty}'><code>{name}: {ty}</code> write!(w, "<span id='{shortty}.{name}' class='{shortty}'><code>{name}: {ty}</code>
</span><span class='stab {stab}'></span>", </span>",
shortty = ItemType::StructField, shortty = ItemType::StructField,
stab = field.stability_class(),
name = field.name.as_ref().unwrap(), name = field.name.as_ref().unwrap(),
ty = ty)?; ty = ty)?;
if let Some(stability_class) = field.stability_class() {
write!(w, "<span class='stab {stab}'></span>",
stab = stability_class)?;
}
write!(w, "</span>")?;
document(w, cx, field)?; document(w, cx, field)?;
} }
} }