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)]
46 #[derive(Copy, Eq, PartialEq, Clone)]
53 impl<'a> From<&'a clean::Item> for ItemType {
54 fn from(item: &'a clean::Item) -> ItemType {
55 let inner = match item.inner {
56 clean::StrippedItem(box ref item) => item,
61 clean::ModuleItem(..) => ItemType::Module,
62 clean::ExternCrateItem(..) => ItemType::ExternCrate,
63 clean::ImportItem(..) => ItemType::Import,
64 clean::StructItem(..) => ItemType::Struct,
65 clean::EnumItem(..) => ItemType::Enum,
66 clean::FunctionItem(..) => ItemType::Function,
67 clean::TypedefItem(..) => ItemType::Typedef,
68 clean::StaticItem(..) => ItemType::Static,
69 clean::ConstantItem(..) => ItemType::Constant,
70 clean::TraitItem(..) => ItemType::Trait,
71 clean::ImplItem(..) => ItemType::Impl,
72 clean::TyMethodItem(..) => ItemType::TyMethod,
73 clean::MethodItem(..) => ItemType::Method,
74 clean::StructFieldItem(..) => ItemType::StructField,
75 clean::VariantItem(..) => ItemType::Variant,
76 clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction
77 clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic
78 clean::MacroItem(..) => ItemType::Macro,
79 clean::PrimitiveItem(..) => ItemType::Primitive,
80 clean::AssociatedConstItem(..) => ItemType::AssociatedConst,
81 clean::AssociatedTypeItem(..) => ItemType::AssociatedType,
82 clean::DefaultImplItem(..) => ItemType::Impl,
83 clean::StrippedItem(..) => unreachable!(),
88 impl From<clean::TypeKind> for ItemType {
89 fn from(kind: clean::TypeKind) -> ItemType {
91 clean::TypeStruct => ItemType::Struct,
92 clean::TypeEnum => ItemType::Enum,
93 clean::TypeFunction => ItemType::Function,
94 clean::TypeTrait => ItemType::Trait,
95 clean::TypeModule => ItemType::Module,
96 clean::TypeStatic => ItemType::Static,
97 clean::TypeConst => ItemType::Constant,
98 clean::TypeVariant => ItemType::Variant,
99 clean::TypeTypedef => ItemType::Typedef,
105 pub fn css_class(&self) -> &'static str {
107 ItemType::Module => "mod",
108 ItemType::ExternCrate => "externcrate",
109 ItemType::Import => "import",
110 ItemType::Struct => "struct",
111 ItemType::Enum => "enum",
112 ItemType::Function => "fn",
113 ItemType::Typedef => "type",
114 ItemType::Static => "static",
115 ItemType::Trait => "trait",
116 ItemType::Impl => "impl",
117 ItemType::TyMethod => "tymethod",
118 ItemType::Method => "method",
119 ItemType::StructField => "structfield",
120 ItemType::Variant => "variant",
121 ItemType::Macro => "macro",
122 ItemType::Primitive => "primitive",
123 ItemType::AssociatedType => "associatedtype",
124 ItemType::Constant => "constant",
125 ItemType::AssociatedConst => "associatedconstant",
129 pub fn name_space(&self) -> NameSpace {
136 ItemType::Primitive |
137 ItemType::AssociatedType => NameSpace::Type,
139 ItemType::ExternCrate |
146 ItemType::StructField |
149 ItemType::AssociatedConst => NameSpace::Value,
151 ItemType::Macro => NameSpace::Macro,
156 impl fmt::Display for ItemType {
157 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
158 self.css_class().fmt(f)
162 pub const NAMESPACE_TYPE: &'static str = "t";
163 pub const NAMESPACE_VALUE: &'static str = "v";
164 pub const NAMESPACE_MACRO: &'static str = "m";
167 pub fn to_static_str(&self) -> &'static str {
169 NameSpace::Type => NAMESPACE_TYPE,
170 NameSpace::Value => NAMESPACE_VALUE,
171 NameSpace::Macro => NAMESPACE_MACRO,
176 impl fmt::Display for NameSpace {
177 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
178 self.to_static_str().fmt(f)