Skip to content

Commit

Permalink
Change BoxIter to avoid trait objects
Browse files Browse the repository at this point in the history
The introduction of object-safety for coercion to trait objects (see
rust-lang/rfcs#255) affects the previous implementation of BoxIter. It turns
out trait objects are not actually necessary to deal with this situation, so
the implementation was changed to be generic over the type of iterator instead
of the type iterated over.
  • Loading branch information
milibopp committed Nov 4, 2014
1 parent dcfaaf3 commit dbdcf13
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/boxiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,29 @@
/// Iterator trait.
///
/// Iterator element type is `A`
pub struct BoxIter<A> {
pub struct BoxIter<I> {
/// The wrapped iterator pointer
pub iter: Box<Iterator<A> + 'static>
pub iter: Box<I>
}

impl<A> BoxIter<A>
impl<A, I> BoxIter<I>
where I: Iterator<A>
{
/// Create a BoxIter from an iterator value
pub fn from_iter<I: 'static + Iterator<A>>(iter: I) -> BoxIter<A>
pub fn from_iter(iter: I) -> BoxIter<I>
{
BoxIter::from_box(box iter as Box<Iterator<A> + 'static>)
BoxIter::from_box(box iter)
}

/// Create a BoxIter from an already boxed iterator
pub fn from_box(iter: Box<Iterator<A> + 'static>) -> BoxIter<A>
pub fn from_box(iter: Box<I>) -> BoxIter<I>
{
BoxIter{iter: iter}
}
}

impl<A> Iterator<A> for BoxIter<A>
impl<A, I> Iterator<A> for BoxIter<I>
where I: Iterator<A>
{
#[inline]
fn next(&mut self) -> Option<A>
Expand Down

0 comments on commit dbdcf13

Please sign in to comment.