Skip to content

Commit

Permalink
make rangeargument methods non-default; simplify impl
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Jan 14, 2017
1 parent 54a3487 commit 58e597e
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/libcollections/range.rs
Expand Up @@ -41,9 +41,7 @@ pub trait RangeArgument<T: ?Sized> {
/// assert_eq!((3..10).start(), Included(&3));
/// # }
/// ```
fn start(&self) -> Bound<&T> {
Unbounded
}
fn start(&self) -> Bound<&T>;

/// End index bound
///
Expand All @@ -66,22 +64,33 @@ pub trait RangeArgument<T: ?Sized> {
/// assert_eq!((3..10).end(), Excluded(&10));
/// # }
/// ```
fn end(&self) -> Bound<&T> {
Unbounded
}
fn end(&self) -> Bound<&T>;
}

// FIXME add inclusive ranges to RangeArgument

impl<T: ?Sized> RangeArgument<T> for RangeFull {}
impl<T: ?Sized> RangeArgument<T> for RangeFull {
fn start(&self) -> Bound<&T> {
Unbounded
}
fn end(&self) -> Bound<&T> {
Unbounded
}
}

impl<T> RangeArgument<T> for RangeFrom<T> {
fn start(&self) -> Bound<&T> {
Included(&self.start)
}
fn end(&self) -> Bound<&T> {
Unbounded
}
}

impl<T> RangeArgument<T> for RangeTo<T> {
fn start(&self) -> Bound<&T> {
Unbounded
}
fn end(&self) -> Bound<&T> {
Excluded(&self.end)
}
Expand Down Expand Up @@ -116,18 +125,10 @@ impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {

impl<'a, T: ?Sized + 'a> RangeArgument<T> for (Bound<&'a T>, Bound<&'a T>) {
fn start(&self) -> Bound<&T> {
match *self {
(Included(start), _) => Included(start),
(Excluded(start), _) => Excluded(start),
(Unbounded, _) => Unbounded,
}
self.0
}

fn end(&self) -> Bound<&T> {
match *self {
(_, Included(end)) => Included(end),
(_, Excluded(end)) => Excluded(end),
(_, Unbounded) => Unbounded,
}
self.1
}
}

0 comments on commit 58e597e

Please sign in to comment.