4 use syntax::ext::base::MacroKind;
7 /// Item type. Corresponds to `clean::ItemEnum` variants.
9 /// The search index uses item types encoded as smaller numbers which equal to
10 /// discriminants. JavaScript then is used to decode them into the original value.
11 /// Consequently, every change to this type should be synchronized to
12 /// the `itemTypes` mapping table in `static/main.js`.
14 /// In addition, code in `html::render` uses this enum to generate CSS classes, page prefixes, and
15 /// module headings. If you are adding to this enum and want to ensure that the sidebar also prints
16 /// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an
17 /// ordering based on a helper function inside `item_module`, in the same file.
18 #[derive(Copy, PartialEq, Clone, Debug)]
49 #[derive(Copy, Eq, PartialEq, Clone)]
57 impl<'a> From<&'a clean::Item> for ItemType {
58 fn from(item: &'a clean::Item) -> ItemType {
59 let inner = match item.inner {
60 clean::StrippedItem(box ref item) => item,
65 clean::ModuleItem(..) => ItemType::Module,
66 clean::ExternCrateItem(..) => ItemType::ExternCrate,
67 clean::ImportItem(..) => ItemType::Import,
68 clean::StructItem(..) => ItemType::Struct,
69 clean::UnionItem(..) => ItemType::Union,
70 clean::EnumItem(..) => ItemType::Enum,
71 clean::FunctionItem(..) => ItemType::Function,
72 clean::TypedefItem(..) => ItemType::Typedef,
73 clean::ExistentialItem(..) => ItemType::Existential,
74 clean::StaticItem(..) => ItemType::Static,
75 clean::ConstantItem(..) => ItemType::Constant,
76 clean::TraitItem(..) => ItemType::Trait,
77 clean::ImplItem(..) => ItemType::Impl,
78 clean::TyMethodItem(..) => ItemType::TyMethod,
79 clean::MethodItem(..) => ItemType::Method,
80 clean::StructFieldItem(..) => ItemType::StructField,
81 clean::VariantItem(..) => ItemType::Variant,
82 clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction
83 clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic
84 clean::MacroItem(..) => ItemType::Macro,
85 clean::PrimitiveItem(..) => ItemType::Primitive,
86 clean::AssociatedConstItem(..) => ItemType::AssociatedConst,
87 clean::AssociatedTypeItem(..) => ItemType::AssociatedType,
88 clean::ForeignTypeItem => ItemType::ForeignType,
89 clean::KeywordItem(..) => ItemType::Keyword,
90 clean::TraitAliasItem(..) => ItemType::TraitAlias,
91 clean::ProcMacroItem(ref mac) => match mac.kind {
92 MacroKind::Bang => ItemType::Macro,
93 MacroKind::Attr => ItemType::ProcAttribute,
94 MacroKind::Derive => ItemType::ProcDerive,
95 MacroKind::ProcMacroStub => unreachable!(),
97 clean::StrippedItem(..) => unreachable!(),
102 impl From<clean::TypeKind> for ItemType {
103 fn from(kind: clean::TypeKind) -> ItemType {
105 clean::TypeKind::Struct => ItemType::Struct,
106 clean::TypeKind::Union => ItemType::Union,
107 clean::TypeKind::Enum => ItemType::Enum,
108 clean::TypeKind::Function => ItemType::Function,
109 clean::TypeKind::Trait => ItemType::Trait,
110 clean::TypeKind::Module => ItemType::Module,
111 clean::TypeKind::Static => ItemType::Static,
112 clean::TypeKind::Const => ItemType::Constant,
113 clean::TypeKind::Variant => ItemType::Variant,
114 clean::TypeKind::Typedef => ItemType::Typedef,
115 clean::TypeKind::Foreign => ItemType::ForeignType,
116 clean::TypeKind::Macro => ItemType::Macro,
117 clean::TypeKind::Attr => ItemType::ProcAttribute,
118 clean::TypeKind::Derive => ItemType::ProcDerive,
119 clean::TypeKind::TraitAlias => ItemType::TraitAlias,
125 pub fn css_class(&self) -> &'static str {
127 ItemType::Module => "mod",
128 ItemType::ExternCrate => "externcrate",
129 ItemType::Import => "import",
130 ItemType::Struct => "struct",
131 ItemType::Union => "union",
132 ItemType::Enum => "enum",
133 ItemType::Function => "fn",
134 ItemType::Typedef => "type",
135 ItemType::Static => "static",
136 ItemType::Trait => "trait",
137 ItemType::Impl => "impl",
138 ItemType::TyMethod => "tymethod",
139 ItemType::Method => "method",
140 ItemType::StructField => "structfield",
141 ItemType::Variant => "variant",
142 ItemType::Macro => "macro",
143 ItemType::Primitive => "primitive",
144 ItemType::AssociatedType => "associatedtype",
145 ItemType::Constant => "constant",
146 ItemType::AssociatedConst => "associatedconstant",
147 ItemType::ForeignType => "foreigntype",
148 ItemType::Keyword => "keyword",
149 ItemType::Existential => "existential",
150 ItemType::ProcAttribute => "attr",
151 ItemType::ProcDerive => "derive",
152 ItemType::TraitAlias => "traitalias",
156 pub fn name_space(&self) -> NameSpace {
164 ItemType::Primitive |
165 ItemType::AssociatedType |
166 ItemType::Existential |
167 ItemType::TraitAlias |
168 ItemType::ForeignType => NameSpace::Type,
170 ItemType::ExternCrate |
177 ItemType::StructField |
180 ItemType::AssociatedConst => NameSpace::Value,
183 ItemType::ProcAttribute |
184 ItemType::ProcDerive => NameSpace::Macro,
186 ItemType::Keyword => NameSpace::Keyword,
191 impl fmt::Display for ItemType {
192 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
193 self.css_class().fmt(f)
197 pub const NAMESPACE_TYPE: &'static str = "t";
198 pub const NAMESPACE_VALUE: &'static str = "v";
199 pub const NAMESPACE_MACRO: &'static str = "m";
200 pub const NAMESPACE_KEYWORD: &'static str = "k";
203 pub fn to_static_str(&self) -> &'static str {
205 NameSpace::Type => NAMESPACE_TYPE,
206 NameSpace::Value => NAMESPACE_VALUE,
207 NameSpace::Macro => NAMESPACE_MACRO,
208 NameSpace::Keyword => NAMESPACE_KEYWORD,
213 impl fmt::Display for NameSpace {
214 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
215 self.to_static_str().fmt(f)