Skip to content

Commit

Permalink
FlatStack: use OffsetContainer iter (#52)
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru authored Jul 2, 2024
1 parent 89fac29 commit f609a31
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ impl<R: Default, S: Default> Default for FlatStack<R, S> {
impl<R: Region, S: OffsetContainer<<R as Region>::Index>> Debug for FlatStack<R, S>
where
for<'a> R::ReadItem<'a>: Debug,
for<'a> &'a S: IntoIterator<Item = &'a R::Index>,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.iter()).finish()
f.debug_list().entries(self).finish()
}
}

Expand Down Expand Up @@ -294,10 +293,7 @@ where
{
/// Iterate the items in this stack.
#[inline]
pub fn iter<'a>(&'a self) -> Iter<'a, R, <&'a S as IntoIterator>::IntoIter>
where
&'a S: IntoIterator<Item = &'a R::Index>,
{
pub fn iter(&self) -> Iter<R, S::Iter<'_>> {
self.into_iter()
}
}
Expand Down Expand Up @@ -331,16 +327,13 @@ where
}
}

impl<'a, R: Region, S: OffsetContainer<<R as Region>::Index>> IntoIterator for &'a FlatStack<R, S>
where
&'a S: IntoIterator<Item = &'a <R as Region>::Index>,
{
impl<'a, R: Region, S: OffsetContainer<<R as Region>::Index>> IntoIterator for &'a FlatStack<R, S> {
type Item = R::ReadItem<'a>;
type IntoIter = Iter<'a, R, <&'a S as IntoIterator>::IntoIter>;
type IntoIter = Iter<'a, R, S::Iter<'a>>;

fn into_iter(self) -> Self::IntoIter {
Iter {
inner: self.indices.into_iter(),
inner: self.indices.iter(),
region: &self.region,
}
}
Expand All @@ -351,7 +344,6 @@ where
pub struct Iter<'a, R, S>
where
R: Region,
S: Iterator<Item = &'a <R as Region>::Index>,
{
/// Iterator over indices.
inner: S,
Expand All @@ -362,12 +354,12 @@ where
impl<'a, R, S> Iterator for Iter<'a, R, S>
where
R: Region,
S: Iterator<Item = &'a <R as Region>::Index>,
S: Iterator<Item = <R as Region>::Index>,
{
type Item = R::ReadItem<'a>;

fn next(&mut self) -> Option<Self::Item> {
self.inner.next().map(|idx| self.region.index(*idx))
self.inner.next().map(|idx| self.region.index(idx))
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand All @@ -378,14 +370,14 @@ where
impl<'a, R, S> ExactSizeIterator for Iter<'a, R, S>
where
R: Region,
S: ExactSizeIterator<Item = &'a <R as Region>::Index>,
S: ExactSizeIterator<Item = <R as Region>::Index>,
{
}

impl<'a, R, S> Clone for Iter<'a, R, S>
where
R: Region,
S: Iterator<Item = &'a <R as Region>::Index> + Clone,
S: Iterator<Item = <R as Region>::Index> + Clone,
{
fn clone(&self) -> Self {
Self {
Expand Down

0 comments on commit f609a31

Please sign in to comment.