Migrate Item ➡ ItemType function to method.

This commit is contained in:
Corey Farwell 2016-09-28 22:53:35 -04:00
parent ea65ab6c7e
commit c66c4533d1
2 changed files with 35 additions and 35 deletions

View File

@ -283,34 +283,34 @@ impl Item {
}
}
pub fn is_mod(&self) -> bool {
ItemType::from(self) == ItemType::Module
self.type_() == ItemType::Module
}
pub fn is_trait(&self) -> bool {
ItemType::from(self) == ItemType::Trait
self.type_() == ItemType::Trait
}
pub fn is_struct(&self) -> bool {
ItemType::from(self) == ItemType::Struct
self.type_() == ItemType::Struct
}
pub fn is_enum(&self) -> bool {
ItemType::from(self) == ItemType::Module
self.type_() == ItemType::Module
}
pub fn is_fn(&self) -> bool {
ItemType::from(self) == ItemType::Function
self.type_() == ItemType::Function
}
pub fn is_associated_type(&self) -> bool {
ItemType::from(self) == ItemType::AssociatedType
self.type_() == ItemType::AssociatedType
}
pub fn is_associated_const(&self) -> bool {
ItemType::from(self) == ItemType::AssociatedConst
self.type_() == ItemType::AssociatedConst
}
pub fn is_method(&self) -> bool {
ItemType::from(self) == ItemType::Method
self.type_() == ItemType::Method
}
pub fn is_ty_method(&self) -> bool {
ItemType::from(self) == ItemType::TyMethod
self.type_() == ItemType::TyMethod
}
pub fn is_primitive(&self) -> bool {
ItemType::from(self) == ItemType::Primitive
self.type_() == ItemType::Primitive
}
pub fn is_stripped(&self) -> bool {
match self.inner { StrippedItem(..) => true, _ => false }
@ -342,6 +342,11 @@ impl Item {
pub fn stable_since(&self) -> Option<&str> {
self.stability.as_ref().map(|s| &s.since[..])
}
/// Returns a documentation-level item type from the item.
pub fn type_(&self) -> ItemType {
ItemType::from(self)
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]

View File

@ -591,7 +591,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
for &(did, ref item) in orphan_impl_items {
if let Some(&(ref fqp, _)) = paths.get(&did) {
search_index.push(IndexItem {
ty: item_type(item),
ty: item.type_(),
name: item.name.clone().unwrap(),
path: fqp[..fqp.len() - 1].join("::"),
desc: Escape(&shorter(item.doc_value())).to_string(),
@ -835,11 +835,6 @@ fn mkdir(path: &Path) -> io::Result<()> {
}
}
/// Returns a documentation-level item type from the item.
fn item_type(item: &clean::Item) -> ItemType {
ItemType::from(item)
}
/// Takes a path to a source file and cleans the path to it. This canonicalizes
/// things like ".." to components which preserve the "top down" hierarchy of a
/// static HTML tree. Each component in the cleaned path will be passed as an
@ -1075,7 +1070,7 @@ impl DocFolder for Cache {
// inserted later on when serializing the search-index.
if item.def_id.index != CRATE_DEF_INDEX {
self.search_index.push(IndexItem {
ty: item_type(&item),
ty: item.type_(),
name: s.to_string(),
path: path.join("::").to_string(),
desc: Escape(&shorter(item.doc_value())).to_string(),
@ -1122,7 +1117,7 @@ impl DocFolder for Cache {
self.access_levels.is_public(item.def_id)
{
self.paths.insert(item.def_id,
(self.stack.clone(), item_type(&item)));
(self.stack.clone(), item.type_()));
}
}
// link variants to their parent enum because pages aren't emitted
@ -1135,7 +1130,7 @@ impl DocFolder for Cache {
clean::PrimitiveItem(..) if item.visibility.is_some() => {
self.paths.insert(item.def_id, (self.stack.clone(),
item_type(&item)));
item.type_()));
}
_ => {}
@ -1304,7 +1299,7 @@ impl Context {
title.push_str(it.name.as_ref().unwrap());
}
title.push_str(" - Rust");
let tyname = item_type(it).css_class();
let tyname = it.type_().css_class();
let desc = if it.is_crate() {
format!("API documentation for the Rust `{}` crate.",
self.shared.layout.krate)
@ -1407,7 +1402,7 @@ impl Context {
// buf will be empty if the item is stripped and there is no redirect for it
if !buf.is_empty() {
let name = item.name.as_ref().unwrap();
let item_type = item_type(&item);
let item_type = item.type_();
let file_name = &item_path(item_type, name);
let joint_dst = self.dst.join(file_name);
try_err!(fs::create_dir_all(&self.dst), &self.dst);
@ -1444,7 +1439,7 @@ impl Context {
for item in &m.items {
if maybe_ignore_item(item) { continue }
let short = item_type(item).css_class();
let short = item.type_().css_class();
let myname = match item.name {
None => continue,
Some(ref s) => s.to_string(),
@ -1541,7 +1536,7 @@ impl<'a> Item<'a> {
}
Some(format!("{path}{file}?gotosrc={goto}",
path = path,
file = item_path(item_type(self.item), external_path.last().unwrap()),
file = item_path(self.item.type_(), external_path.last().unwrap()),
goto = self.item.def_id.index.as_usize()))
}
}
@ -1586,7 +1581,7 @@ impl<'a> fmt::Display for Item<'a> {
}
}
write!(fmt, "<a class='{}' href=''>{}</a>",
item_type(self.item), self.item.name.as_ref().unwrap())?;
self.item.type_(), self.item.name.as_ref().unwrap())?;
write!(fmt, "</span>")?; // in-band
write!(fmt, "<span class='out-of-band'>")?;
@ -1739,8 +1734,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
}
fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering {
let ty1 = item_type(i1);
let ty2 = item_type(i2);
let ty1 = i1.type_();
let ty2 = i2.type_();
if ty1 != ty2 {
return (reorder(ty1), idx1).cmp(&(reorder(ty2), idx2))
}
@ -1764,7 +1759,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
continue;
}
let myty = Some(item_type(myitem));
let myty = Some(myitem.type_());
if curty == Some(ItemType::ExternCrate) && myty == Some(ItemType::Import) {
// Put `extern crate` and `use` re-exports in the same section.
curty = myty;
@ -1851,9 +1846,9 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
name = *myitem.name.as_ref().unwrap(),
stab_docs = stab_docs,
docs = shorter(Some(&Markdown(doc_value).to_string())),
class = item_type(myitem),
class = myitem.type_(),
stab = myitem.stability_class(),
href = item_path(item_type(myitem), myitem.name.as_ref().unwrap()),
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
title = full_path(cx, myitem))?;
}
}
@ -2059,7 +2054,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean::Item)
-> fmt::Result {
let name = m.name.as_ref().unwrap();
let item_type = item_type(m);
let item_type = m.type_();
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h3 id='{id}' class='method stab {stab}'>\
@ -2145,7 +2140,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
let (ref path, _) = cache.external_paths[&it.def_id];
path[..path.len() - 1].join("/")
},
ty = item_type(it).css_class(),
ty = it.type_().css_class(),
name = *it.name.as_ref().unwrap())?;
Ok(())
}
@ -2154,7 +2149,7 @@ fn naive_assoc_href(it: &clean::Item, link: AssocItemLink) -> String {
use html::item_type::ItemType::*;
let name = it.name.as_ref().unwrap();
let ty = match item_type(it) {
let ty = match it.type_() {
Typedef | AssociatedType => AssociatedType,
s@_ => s,
};
@ -2232,7 +2227,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
link: AssocItemLink)
-> fmt::Result {
let name = meth.name.as_ref().unwrap();
let anchor = format!("#{}.{}", item_type(meth), name);
let anchor = format!("#{}.{}", meth.type_(), name);
let href = match link {
AssocItemLink::Anchor(Some(ref id)) => format!("#{}", id),
AssocItemLink::Anchor(None) => anchor,
@ -2740,7 +2735,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
link: AssocItemLink, render_mode: RenderMode,
is_default_item: bool, outer_version: Option<&str>,
trait_: Option<&clean::Trait>) -> fmt::Result {
let item_type = item_type(item);
let item_type = item.type_();
let name = item.name.as_ref().unwrap();
let render_method_item: bool = match render_mode {
@ -2932,7 +2927,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
relpath: '{path}'\
}};</script>",
name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""),
ty = item_type(it).css_class(),
ty = it.type_().css_class(),
path = relpath)?;
if parentlen == 0 {
// there is no sidebar-items.js beyond the crate root path