@@ -137,12 +137,7 @@ impl Path {
137
137
Path {
138
138
span : s,
139
139
global : false ,
140
- segments : vec ! [
141
- PathSegment {
142
- identifier: identifier,
143
- parameters: PathParameters :: none( )
144
- }
145
- ] ,
140
+ segments : vec ! [ identifier. into( ) ] ,
146
141
}
147
142
}
148
143
}
@@ -160,7 +155,15 @@ pub struct PathSegment {
160
155
/// this is more than just simple syntactic sugar; the use of
161
156
/// parens affects the region binding rules, so we preserve the
162
157
/// distinction.
163
- pub parameters : PathParameters ,
158
+ /// The `Option<P<..>>` wrapper is purely a size optimization;
159
+ /// `None` is used to represent both `Path` and `Path<>`.
160
+ pub parameters : Option < P < PathParameters > > ,
161
+ }
162
+
163
+ impl From < Ident > for PathSegment {
164
+ fn from ( id : Ident ) -> Self {
165
+ PathSegment { identifier : id, parameters : None }
166
+ }
164
167
}
165
168
166
169
/// Parameters of a path segment.
@@ -174,79 +177,8 @@ pub enum PathParameters {
174
177
Parenthesized ( ParenthesizedParameterData ) ,
175
178
}
176
179
177
- impl PathParameters {
178
- pub fn none ( ) -> PathParameters {
179
- PathParameters :: AngleBracketed ( AngleBracketedParameterData {
180
- lifetimes : Vec :: new ( ) ,
181
- types : P :: new ( ) ,
182
- bindings : P :: new ( ) ,
183
- } )
184
- }
185
-
186
- pub fn is_empty ( & self ) -> bool {
187
- match * self {
188
- PathParameters :: AngleBracketed ( ref data) => data. is_empty ( ) ,
189
-
190
- // Even if the user supplied no types, something like
191
- // `X()` is equivalent to `X<(),()>`.
192
- PathParameters :: Parenthesized ( ..) => false ,
193
- }
194
- }
195
-
196
- pub fn has_lifetimes ( & self ) -> bool {
197
- match * self {
198
- PathParameters :: AngleBracketed ( ref data) => !data. lifetimes . is_empty ( ) ,
199
- PathParameters :: Parenthesized ( _) => false ,
200
- }
201
- }
202
-
203
- pub fn has_types ( & self ) -> bool {
204
- match * self {
205
- PathParameters :: AngleBracketed ( ref data) => !data. types . is_empty ( ) ,
206
- PathParameters :: Parenthesized ( ..) => true ,
207
- }
208
- }
209
-
210
- /// Returns the types that the user wrote. Note that these do not necessarily map to the type
211
- /// parameters in the parenthesized case.
212
- pub fn types ( & self ) -> Vec < & P < Ty > > {
213
- match * self {
214
- PathParameters :: AngleBracketed ( ref data) => {
215
- data. types . iter ( ) . collect ( )
216
- }
217
- PathParameters :: Parenthesized ( ref data) => {
218
- data. inputs . iter ( )
219
- . chain ( data. output . iter ( ) )
220
- . collect ( )
221
- }
222
- }
223
- }
224
-
225
- pub fn lifetimes ( & self ) -> Vec < & Lifetime > {
226
- match * self {
227
- PathParameters :: AngleBracketed ( ref data) => {
228
- data. lifetimes . iter ( ) . collect ( )
229
- }
230
- PathParameters :: Parenthesized ( _) => {
231
- Vec :: new ( )
232
- }
233
- }
234
- }
235
-
236
- pub fn bindings ( & self ) -> Vec < & TypeBinding > {
237
- match * self {
238
- PathParameters :: AngleBracketed ( ref data) => {
239
- data. bindings . iter ( ) . collect ( )
240
- }
241
- PathParameters :: Parenthesized ( _) => {
242
- Vec :: new ( )
243
- }
244
- }
245
- }
246
- }
247
-
248
180
/// A path like `Foo<'a, T>`
249
- #[ derive( Clone , PartialEq , Eq , RustcEncodable , RustcDecodable , Hash , Debug ) ]
181
+ #[ derive( Clone , PartialEq , Eq , RustcEncodable , RustcDecodable , Hash , Debug , Default ) ]
250
182
pub struct AngleBracketedParameterData {
251
183
/// The lifetime parameters for this path segment.
252
184
pub lifetimes : Vec < Lifetime > ,
@@ -258,9 +190,10 @@ pub struct AngleBracketedParameterData {
258
190
pub bindings : P < [ TypeBinding ] > ,
259
191
}
260
192
261
- impl AngleBracketedParameterData {
262
- fn is_empty ( & self ) -> bool {
263
- self . lifetimes . is_empty ( ) && self . types . is_empty ( ) && self . bindings . is_empty ( )
193
+ impl Into < Option < P < PathParameters > > > for AngleBracketedParameterData {
194
+ fn into ( self ) -> Option < P < PathParameters > > {
195
+ let empty = self . lifetimes . is_empty ( ) && self . types . is_empty ( ) && self . bindings . is_empty ( ) ;
196
+ if empty { None } else { Some ( P ( PathParameters :: AngleBracketed ( self ) ) ) }
264
197
}
265
198
}
266
199
0 commit comments