use crate::iter::{ConstIntoIter, IsIteratorKind};
pub const fn repeat<T: Copy>(val: T) -> Repeat<T> {
Repeat(val)
}
pub struct Repeat<T>(T);
impl<T> ConstIntoIter for Repeat<T> {
type Kind = IsIteratorKind;
type IntoIter = Self;
type Item = T;
const ITEMS_NEED_DROP: bool = false;
}
impl<T: Copy> Repeat<T> {
pub const fn next(&mut self) -> Option<T> {
Some(self.0)
}
pub const fn next_back(&mut self) -> Option<T> {
Some(self.0)
}
pub const fn rev(self) -> Self {
self
}
pub const fn copy(&self) -> Self {
Self(self.0)
}
}
pub const fn repeat_n<T: Copy>(val: T, count: usize) -> RepeatN<T> {
RepeatN { val, count }
}
pub struct RepeatN<T> {
val: T,
count: usize,
}
impl<T> ConstIntoIter for RepeatN<T> {
type Kind = IsIteratorKind;
type IntoIter = Self;
type Item = T;
const ITEMS_NEED_DROP: bool = false;
}
impl<T: Copy> RepeatN<T> {
pub const fn next(&mut self) -> Option<T> {
if let Some(ncount) = self.count.checked_sub(1) {
self.count = ncount;
Some(self.val)
} else {
None
}
}
pub const fn next_back(&mut self) -> Option<T> {
self.next()
}
pub const fn rev(self) -> Self {
self
}
pub const fn copy(&self) -> Self {
Self { ..*self }
}
}