Skip to content

Commit 9af890e

Browse files
committed
Stop using private variants
1 parent 7111d8a commit 9af890e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/types/range.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,21 @@ impl<'a, S: BoundSided, T: Ord> Ord for OptBound<'a, S, T> {
258258
}
259259

260260
/// Represents a range of values.
261+
#[deriving(Eq, Clone)]
262+
pub struct Range<T> {
263+
priv inner: InnerRange<T>,
264+
}
265+
261266
#[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>>)
266271
}
267272

268273
impl<T: fmt::Show> fmt::Show for Range<T> {
269274
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
270-
match *self {
275+
match self.inner {
271276
Empty => formatter.buf.write_str("empty"),
272277
Normal(ref lower, ref upper) => {
273278
match *lower {
@@ -300,47 +305,47 @@ impl<T: Ord+Normalizable> Range<T> {
300305
_ => lower.value >= upper.value
301306
};
302307
if empty {
303-
return Empty;
308+
return Range { inner: Empty };
304309
}
305310
}
306311
_ => {}
307312
}
308313

309-
Normal(lower, upper)
314+
Range { inner: Normal(lower, upper) }
310315
}
311316

312317
/// Creates a new empty range.
313318
pub fn empty() -> Range<T> {
314-
Empty
319+
Range { inner: Empty }
315320
}
316321

317322
/// Determines if this range is the empty range.
318323
pub fn is_empty(&self) -> bool {
319-
match *self {
324+
match self.inner {
320325
Empty => true,
321326
Normal(..) => false
322327
}
323328
}
324329

325330
/// Returns the lower bound if it exists.
326331
pub fn lower<'a>(&'a self) -> Option<&'a RangeBound<LowerBound, T>> {
327-
match *self {
332+
match self.inner {
328333
Normal(Some(ref lower), _) => Some(lower),
329334
_ => None
330335
}
331336
}
332337

333338
/// Returns the upper bound if it exists.
334339
pub fn upper<'a>(&'a self) -> Option<&'a RangeBound<UpperBound, T>> {
335-
match *self {
340+
match self.inner {
336341
Normal(_, Some(ref upper)) => Some(upper),
337342
_ => None
338343
}
339344
}
340345

341346
/// Determines if a value lies within this range.
342347
pub fn contains(&self, value: &T) -> bool {
343-
match *self {
348+
match self.inner {
344349
Empty => false,
345350
Normal(ref lower, ref upper) => {
346351
lower.as_ref().map_or(true, |b| b.in_bounds(value)) &&

0 commit comments

Comments
 (0)