Skip to content

Commit

Permalink
rustdoc: add namespaces for items
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Aug 3, 2016
1 parent 9bcf986 commit b6bd1ce
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/librustdoc/html/item_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ pub enum ItemType {
AssociatedConst = 18,
}


#[derive(Copy, Eq, PartialEq, Clone)]
pub enum NameSpace {
Type,
Value,
Macro,
}

impl ItemType {
pub fn from_item(item: &clean::Item) -> ItemType {
let inner = match item.inner {
Expand Down Expand Up @@ -113,10 +121,50 @@ impl ItemType {
ItemType::AssociatedConst => "associatedconstant",
}
}

pub fn name_space(&self) -> NameSpace {
match *self {
ItemType::Struct |
ItemType::Enum |
ItemType::Module |
ItemType::Typedef |
ItemType::Trait |
ItemType::Primitive |
ItemType::AssociatedType => NameSpace::Type,

ItemType::ExternCrate |
ItemType::Import |
ItemType::Function |
ItemType::Static |
ItemType::Impl |
ItemType::TyMethod |
ItemType::Method |
ItemType::StructField |
ItemType::Variant |
ItemType::Constant |
ItemType::AssociatedConst => NameSpace::Value,

ItemType::Macro => NameSpace::Macro,
}
}
}

impl fmt::Display for ItemType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.css_class().fmt(f)
}
}

pub const NAMESPACE_TYPE: &'static str = "t";
pub const NAMESPACE_VALUE: &'static str = "v";
pub const NAMESPACE_MACRO: &'static str = "m";

impl NameSpace {
pub fn to_static_str(&self) -> &'static str {
match *self {
NameSpace::Type => NAMESPACE_TYPE,
NameSpace::Value => NAMESPACE_VALUE,
NameSpace::Macro => NAMESPACE_MACRO,
}
}
}

0 comments on commit b6bd1ce

Please sign in to comment.