orx-iterable 1.3.0

Defines and implements Iterable, Collection and CollectionMut traits to represent types that can be iterated over multiple times.
Documentation
use crate::Iterable;

/// An iterable which yields the same value infinitely many times.
pub struct Repeat<T>
where
    T: Clone,
{
    pub(crate) value: T,
}

impl<T> Iterable for Repeat<T>
where
    T: Clone,
{
    type Item = T;

    type Iter = core::iter::Repeat<T>;

    fn iter(&self) -> Self::Iter {
        core::iter::repeat(self.value.clone())
    }
}

impl<T> Iterable for core::iter::Repeat<T>
where
    T: Clone,
{
    type Item = T;

    type Iter = core::iter::Repeat<T>;

    fn iter(&self) -> Self::Iter {
        self.clone()
    }
}

/// Creates an iterable which yields the same value infinitely many times.
pub fn repeat<T>(value: T) -> Repeat<T>
where
    T: Clone,
{
    Repeat { value }
}