macro_tools/
name.rs

1//!
2//! Tait to getn name of an Item.
3//!
4
5/// Define a private namespace for all its items.
6mod private 
7{
8
9  ///
10  /// Trait to get name of an syntax element.
11  ///
12  pub trait Name {
13  /// Get name.
14  fn name( &self ) -> String;
15 }
16
17  impl Name for syn ::Item 
18  {
19  fn name( &self ) -> String 
20  {
21   match self 
22   {
23  syn ::Item ::Const(item) => item.name(),
24  syn ::Item ::Enum(item) => item.name(),
25  syn ::Item ::ExternCrate(item) => item.name(),
26  syn ::Item ::Fn(item) => item.name(),
27  // syn ::Item ::ForeignMod( item ) => item.name(),
28  syn ::Item ::Impl(item) => item.name(),
29  syn ::Item ::Macro(item) => item.name(),
30  // syn ::Item ::Macro2( item ) => item.name(),
31  syn ::Item ::Mod(item) => item.name(),
32  syn ::Item ::Static(item) => item.name(),
33  syn ::Item ::Struct(item) => item.name(),
34  syn ::Item ::Trait(item) => item.name(),
35  syn ::Item ::TraitAlias(item) => item.name(),
36  syn ::Item ::Type(item) => item.name(),
37  syn ::Item ::Union(item) => item.name(),
38  // syn ::Item ::Use( item ) => item.name(),
39  // syn ::Item ::Verbatim( item ) => item.name(),
40  _ => String ::new(),
41 }
42 }
43 }
44
45  impl Name for syn ::Path 
46  {
47  fn name( &self ) -> String 
48  {
49   let first = self.segments.first();
50   if first.is_none() 
51   {
52  return String ::new();
53 }
54   let first = first.unwrap();
55   first.ident.to_string()
56 }
57 }
58
59  impl Name for syn ::ItemConst 
60  {
61  fn name( &self ) -> String 
62  {
63   self.ident.to_string()
64 }
65 }
66
67  impl Name for syn ::ItemEnum 
68  {
69  fn name( &self ) -> String 
70  {
71   self.ident.to_string()
72 }
73 }
74
75  impl Name for syn ::ItemExternCrate 
76  {
77  fn name( &self ) -> String 
78  {
79   self.ident.to_string()
80 }
81 }
82
83  impl Name for syn ::ItemFn 
84  {
85  fn name( &self ) -> String 
86  {
87   self.sig.ident.to_string()
88 }
89 }
90
91  // impl Name for syn ::ItemForeignMod
92  // {
93  //   fn name( &self ) -> String
94  //   {
95  //     self.ident.to_string()
96  // }
97  // }
98
99  impl Name for syn ::ItemImpl 
100  {
101  fn name( &self ) -> String 
102  {
103   if self.trait_.is_none() 
104   {
105  return String ::new();
106 }
107   let t = self.trait_.as_ref().unwrap();
108   t.1.name()
109 }
110 }
111
112  impl Name for syn ::ItemMacro 
113  {
114  fn name( &self ) -> String 
115  {
116   if self.ident.is_none() 
117   {
118  return String ::new();
119 }
120   let ident = self.ident.as_ref().unwrap();
121   ident.to_string()
122 }
123 }
124
125  // impl Name for syn ::ItemMacro2
126  // {
127  //   fn name( &self ) -> String
128  //   {
129  //     self.ident.to_string()
130  // }
131  // }
132
133  impl Name for syn ::ItemMod 
134  {
135  fn name( &self ) -> String 
136  {
137   self.ident.to_string()
138 }
139 }
140
141  impl Name for syn ::ItemStatic 
142  {
143  fn name( &self ) -> String 
144  {
145   self.ident.to_string()
146 }
147 }
148
149  impl Name for syn ::ItemStruct 
150  {
151  fn name( &self ) -> String 
152  {
153   self.ident.to_string()
154 }
155 }
156
157  impl Name for syn ::ItemTrait 
158  {
159  fn name( &self ) -> String 
160  {
161   self.ident.to_string()
162 }
163 }
164
165  impl Name for syn ::ItemTraitAlias 
166  {
167  fn name( &self ) -> String 
168  {
169   self.ident.to_string()
170 }
171 }
172
173  impl Name for syn ::ItemType 
174  {
175  fn name( &self ) -> String 
176  {
177   self.ident.to_string()
178 }
179 }
180
181  impl Name for syn ::ItemUnion 
182  {
183  fn name( &self ) -> String 
184  {
185   self.ident.to_string()
186 }
187 }
188
189  // impl Name for syn ::ItemUse
190  // {
191  //   fn name( &self ) -> String
192  //   {
193  //     self.ident.to_string()
194  // }
195  // }
196
197  // impl Name for syn ::ItemVerbatim
198  // {
199  //   fn name( &self ) -> String
200  //   {
201  //     self.ident.to_string()
202  // }
203  // }
204
205  //
206  //     Const(ItemConst),
207  //     Enum(ItemEnum),
208  //     ExternCrate(ItemExternCrate),
209  //     Fn(ItemFn),
210  //     ForeignMod(ItemForeignMod),
211  //     Impl(ItemImpl),
212  //     Macro(ItemMacro),
213  //     Macro2(ItemMacro2),
214  //     Mod(ItemMod),
215  //     Static(ItemStatic),
216  //     Struct(ItemStruct),
217  //     Trait(ItemTrait),
218  //     TraitAlias(ItemTraitAlias),
219  //     Type(ItemType),
220  //     Union(ItemUnion),
221  //     Use(ItemUse),
222  //     Verbatim(TokenStream),
223}
224
225#[ doc( inline ) ]
226#[ allow( unused_imports ) ]
227pub use own :: *;
228
229/// Own namespace of the module.
230#[ allow( unused_imports ) ]
231pub mod own 
232{
233
234  use super :: *;
235  #[ doc( inline ) ]
236  pub use orphan :: *;
237}
238
239/// Orphan namespace of the module.
240#[ allow( unused_imports ) ]
241pub mod orphan 
242{
243
244  use super :: *;
245  #[ doc( inline ) ]
246  pub use exposed :: *;
247}
248
249/// Exposed namespace of the module.
250#[ allow( unused_imports ) ]
251pub mod exposed 
252{
253
254  use super :: *;
255
256  pub use super ::super ::name;
257  // pub use super ::own as name;
258
259  #[ doc( inline ) ]
260  pub use prelude :: *;
261}
262
263/// Prelude to use essentials: `use my_module ::prelude :: *`.
264#[ allow( unused_imports ) ]
265pub mod prelude 
266{
267
268  use super :: *;
269  #[ doc( inline ) ]
270  #[ allow( unused_imports ) ]
271  pub use private ::Name;
272}