]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: add namespaces for items
authorNick Cameron <ncameron@mozilla.com>
Wed, 3 Aug 2016 01:19:06 +0000 (13:19 +1200)
committerNick Cameron <ncameron@mozilla.com>
Tue, 16 Aug 2016 22:30:39 +0000 (10:30 +1200)
src/librustdoc/html/item_type.rs

index c3d38637ab70ccfc7f0f3db07c625a690c792f81..039f385d7c564612e067098b3aa4e29df36de09c 100644 (file)
@@ -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 {
@@ -113,6 +121,32 @@ pub fn css_class(&self) -> &'static str {
             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 {
@@ -120,3 +154,17 @@ 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,
+        }
+    }
+}