1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
16 /// Item type. Corresponds to `clean::ItemEnum` variants.
18 /// The search index uses item types encoded as smaller numbers which equal to
19 /// discriminants. JavaScript then is used to decode them into the original value.
20 /// Consequently, every change to this type should be synchronized to
21 /// the `itemTypes` mapping table in `static/main.js`.
22 #[derive(Copy, PartialEq, Clone)]
47 #[derive(Copy, Eq, PartialEq, Clone)]
54 impl<'a> From<&'a clean::Item> for ItemType {
55 fn from(item: &'a clean::Item) -> ItemType {
56 let inner = match item.inner {
57 clean::StrippedItem(box ref item) => item,
62 clean::ModuleItem(..) => ItemType::Module,
63 clean::ExternCrateItem(..) => ItemType::ExternCrate,
64 clean::ImportItem(..) => ItemType::Import,
65 clean::StructItem(..) => ItemType::Struct,
66 clean::UnionItem(..) => ItemType::Union,
67 clean::EnumItem(..) => ItemType::Enum,
68 clean::FunctionItem(..) => ItemType::Function,
69 clean::TypedefItem(..) => ItemType::Typedef,
70 clean::StaticItem(..) => ItemType::Static,
71 clean::ConstantItem(..) => ItemType::Constant,
72 clean::TraitItem(..) => ItemType::Trait,
73 clean::ImplItem(..) => ItemType::Impl,
74 clean::TyMethodItem(..) => ItemType::TyMethod,
75 clean::MethodItem(..) => ItemType::Method,
76 clean::StructFieldItem(..) => ItemType::StructField,
77 clean::VariantItem(..) => ItemType::Variant,
78 clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction
79 clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic
80 clean::MacroItem(..) => ItemType::Macro,
81 clean::PrimitiveItem(..) => ItemType::Primitive,
82 clean::AssociatedConstItem(..) => ItemType::AssociatedConst,
83 clean::AssociatedTypeItem(..) => ItemType::AssociatedType,
84 clean::DefaultImplItem(..) => ItemType::Impl,
85 clean::StrippedItem(..) => unreachable!(),
90 impl From<clean::TypeKind> for ItemType {
91 fn from(kind: clean::TypeKind) -> ItemType {
93 clean::TypeKind::Struct => ItemType::Struct,
94 clean::TypeKind::Union => ItemType::Union,
95 clean::TypeKind::Enum => ItemType::Enum,
96 clean::TypeKind::Function => ItemType::Function,
97 clean::TypeKind::Trait => ItemType::Trait,
98 clean::TypeKind::Module => ItemType::Module,
99 clean::TypeKind::Static => ItemType::Static,
100 clean::TypeKind::Const => ItemType::Constant,
101 clean::TypeKind::Variant => ItemType::Variant,
102 clean::TypeKind::Typedef => ItemType::Typedef,
108 pub fn css_class(&self) -> &'static str {
110 ItemType::Module => "mod",
111 ItemType::ExternCrate => "externcrate",
112 ItemType::Import => "import",
113 ItemType::Struct => "struct",
114 ItemType::Union => "union",
115 ItemType::Enum => "enum",
116 ItemType::Function => "fn",
117 ItemType::Typedef => "type",
118 ItemType::Static => "static",
119 ItemType::Trait => "trait",
120 ItemType::Impl => "impl",
121 ItemType::TyMethod => "tymethod",
122 ItemType::Method => "method",
123 ItemType::StructField => "structfield",
124 ItemType::Variant => "variant",
125 ItemType::Macro => "macro",
126 ItemType::Primitive => "primitive",
127 ItemType::AssociatedType => "associatedtype",
128 ItemType::Constant => "constant",
129 ItemType::AssociatedConst => "associatedconstant",
133 pub fn name_space(&self) -> NameSpace {
141 ItemType::Primitive |
142 ItemType::AssociatedType => NameSpace::Type,
144 ItemType::ExternCrate |
151 ItemType::StructField |
154 ItemType::AssociatedConst => NameSpace::Value,
156 ItemType::Macro => NameSpace::Macro,
161 impl fmt::Display for ItemType {
162 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
163 self.css_class().fmt(f)
167 pub const NAMESPACE_TYPE: &'static str = "t";
168 pub const NAMESPACE_VALUE: &'static str = "v";
169 pub const NAMESPACE_MACRO: &'static str = "m";
172 pub fn to_static_str(&self) -> &'static str {
174 NameSpace::Type => NAMESPACE_TYPE,
175 NameSpace::Value => NAMESPACE_VALUE,
176 NameSpace::Macro => NAMESPACE_MACRO,
181 impl fmt::Display for NameSpace {
182 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
183 self.to_static_str().fmt(f)