@@ -258,16 +258,21 @@ impl<'a, S: BoundSided, T: Ord> Ord for OptBound<'a, S, T> {
258
258
}
259
259
260
260
/// Represents a range of values.
261
+ #[ deriving( Eq , Clone ) ]
262
+ pub struct Range < T > {
263
+ priv inner : InnerRange < T > ,
264
+ }
265
+
261
266
#[ deriving( Eq , Clone ) ]
262
- pub enum Range < T > {
263
- priv Empty ,
264
- priv Normal ( Option < RangeBound < LowerBound , T > > ,
265
- Option < RangeBound < UpperBound , T > > )
267
+ enum InnerRange < T > {
268
+ Empty ,
269
+ Normal ( Option < RangeBound < LowerBound , T > > ,
270
+ Option < RangeBound < UpperBound , T > > )
266
271
}
267
272
268
273
impl < T : fmt:: Show > fmt:: Show for Range < T > {
269
274
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
270
- match * self {
275
+ match self . inner {
271
276
Empty => formatter. buf . write_str ( "empty" ) ,
272
277
Normal ( ref lower, ref upper) => {
273
278
match * lower {
@@ -300,47 +305,47 @@ impl<T: Ord+Normalizable> Range<T> {
300
305
_ => lower. value >= upper. value
301
306
} ;
302
307
if empty {
303
- return Empty ;
308
+ return Range { inner : Empty } ;
304
309
}
305
310
}
306
311
_ => { }
307
312
}
308
313
309
- Normal ( lower, upper)
314
+ Range { inner : Normal ( lower, upper) }
310
315
}
311
316
312
317
/// Creates a new empty range.
313
318
pub fn empty ( ) -> Range < T > {
314
- Empty
319
+ Range { inner : Empty }
315
320
}
316
321
317
322
/// Determines if this range is the empty range.
318
323
pub fn is_empty ( & self ) -> bool {
319
- match * self {
324
+ match self . inner {
320
325
Empty => true ,
321
326
Normal ( ..) => false
322
327
}
323
328
}
324
329
325
330
/// Returns the lower bound if it exists.
326
331
pub fn lower < ' a > ( & ' a self ) -> Option < & ' a RangeBound < LowerBound , T > > {
327
- match * self {
332
+ match self . inner {
328
333
Normal ( Some ( ref lower) , _) => Some ( lower) ,
329
334
_ => None
330
335
}
331
336
}
332
337
333
338
/// Returns the upper bound if it exists.
334
339
pub fn upper < ' a > ( & ' a self ) -> Option < & ' a RangeBound < UpperBound , T > > {
335
- match * self {
340
+ match self . inner {
336
341
Normal ( _, Some ( ref upper) ) => Some ( upper) ,
337
342
_ => None
338
343
}
339
344
}
340
345
341
346
/// Determines if a value lies within this range.
342
347
pub fn contains ( & self , value : & T ) -> bool {
343
- match * self {
348
+ match self . inner {
344
349
Empty => false ,
345
350
Normal ( ref lower, ref upper) => {
346
351
lower. as_ref ( ) . map_or ( true , |b| b. in_bounds ( value) ) &&
0 commit comments