orx_iterable/obj_safe/sources/
repeat_n.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::{obj_safe::IterableObj, sources::RepeatN};
use std::boxed::Box;

impl<T> IterableObj for RepeatN<T>
where
    T: Clone,
{
    type Item = T;

    fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
        Box::new(core::iter::repeat_n(self.value.clone(), self.count))
    }
}

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

    fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
        Box::new(self.clone())
    }
}