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)]
37 // we used to have ForeignFunction and ForeignStatic. they are retired now.
45 pub fn from_item(item: &clean::Item) -> ItemType {
47 clean::ModuleItem(..) => ItemType::Module,
48 clean::StructItem(..) => ItemType::Struct,
49 clean::EnumItem(..) => ItemType::Enum,
50 clean::FunctionItem(..) => ItemType::Function,
51 clean::TypedefItem(..) => ItemType::Typedef,
52 clean::StaticItem(..) => ItemType::Static,
53 clean::ConstantItem(..) => ItemType::Constant,
54 clean::TraitItem(..) => ItemType::Trait,
55 clean::ImplItem(..) => ItemType::Impl,
56 clean::ViewItemItem(..) => ItemType::ViewItem,
57 clean::TyMethodItem(..) => ItemType::TyMethod,
58 clean::MethodItem(..) => ItemType::Method,
59 clean::StructFieldItem(..) => ItemType::StructField,
60 clean::VariantItem(..) => ItemType::Variant,
61 clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction
62 clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic
63 clean::MacroItem(..) => ItemType::Macro,
64 clean::PrimitiveItem(..) => ItemType::Primitive,
65 clean::AssociatedTypeItem(..) => ItemType::AssociatedType,
69 pub fn from_type_kind(kind: clean::TypeKind) -> ItemType {
71 clean::TypeStruct => ItemType::Struct,
72 clean::TypeEnum => ItemType::Enum,
73 clean::TypeFunction => ItemType::Function,
74 clean::TypeTrait => ItemType::Trait,
75 clean::TypeModule => ItemType::Module,
76 clean::TypeStatic => ItemType::Static,
77 clean::TypeConst => ItemType::Constant,
78 clean::TypeVariant => ItemType::Variant,
79 clean::TypeTypedef => ItemType::Typedef,
83 pub fn to_static_str(&self) -> &'static str {
85 ItemType::Module => "mod",
86 ItemType::Struct => "struct",
87 ItemType::Enum => "enum",
88 ItemType::Function => "fn",
89 ItemType::Typedef => "type",
90 ItemType::Static => "static",
91 ItemType::Trait => "trait",
92 ItemType::Impl => "impl",
93 ItemType::ViewItem => "viewitem",
94 ItemType::TyMethod => "tymethod",
95 ItemType::Method => "method",
96 ItemType::StructField => "structfield",
97 ItemType::Variant => "variant",
98 ItemType::Macro => "macro",
99 ItemType::Primitive => "primitive",
100 ItemType::AssociatedType => "associatedtype",
101 ItemType::Constant => "constant",
106 impl fmt::Show for ItemType {
107 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
108 self.to_static_str().fmt(f)