Skip to content

Add additional iterator traits for DistIter #618

@Lucretiel

Description

@Lucretiel

impl<'a, D, R, T> Iterator for DistIter<'a, D, R, T>
where D: Distribution<T>, R: Rng + 'a
{
type Item = T;
#[inline(always)]
fn next(&mut self) -> Option<T> {
Some(self.distr.sample(self.rng))
}
fn size_hint(&self) -> (usize, Option<usize>) {
(usize::max_value(), None)
}
}

The DistIter iterator might benefit from the following additional implementations:

  • DoubleEndedIterator
  • TrustedLen
  • FusedIterator

Additionally, it's recommended that custom iterators implement try_fold, which is the base method used for all other non-lazy iterator operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions