use crate::frontend::iter::impl_iterable_indexed;
use crate::prelude::*;
use super::SliceExpand;
impl<E: CubePrimitive> SliceExpand<E> {
pub fn __expand_iter_method(&self, _scope: &Scope) -> IterExpand<'_, E> {
IterExpand { slice: self }
}
pub fn __expand_iter_mut_method(&mut self, _scope: &Scope) -> IterMutExpand<'_, E> {
IterMutExpand { slice: self }
}
}
pub struct IterExpand<'a, E: CubePrimitive> {
slice: &'a SliceExpand<E>,
}
impl_iterable_indexed!(['a, E: CubePrimitive] IterExpand<'a, E>, &'a NativeExpand<E>);
impl<E: CubePrimitive> IndexedIteratorExpand for IterExpand<'_, E> {
fn __expand_len_method(&self, scope: &Scope) -> NativeExpand<usize> {
self.slice.__expand_len_method(scope)
}
fn get(&mut self, scope: &Scope, index: NativeExpand<usize>) -> Self::Item {
let slice = self.slice;
slice.__expand_index_method(scope, index)
}
}
pub struct IterMutExpand<'a, E: CubePrimitive> {
slice: &'a SliceExpand<E>,
}
impl_iterable_indexed!(['a, E: CubePrimitive] IterMutExpand<'a, E>, &'a mut NativeExpand<E>);
impl<E: CubePrimitive> IndexedIteratorExpand for IterMutExpand<'_, E> {
fn __expand_len_method(&self, scope: &Scope) -> NativeExpand<usize> {
self.slice.__expand_len_method(scope)
}
fn get(&mut self, scope: &Scope, index: NativeExpand<usize>) -> Self::Item {
let slice = self.slice;
slice
.__expand_as_mut_unchecked_method(scope)
.__expand_index_mut_method(scope, index)
}
}
impl<'a, E: CubePrimitive> IntoIteratorExpand for &'a SliceExpand<E> {
type IntoIter = IterExpand<'a, E>;
fn __expand_into_iter_method(self, scope: &Scope) -> Self::IntoIter {
self.__expand_iter_method(scope)
}
}
impl<'a, E: CubePrimitive> IntoIteratorExpand for &'a mut SliceExpand<E> {
type IntoIter = IterMutExpand<'a, E>;
fn __expand_into_iter_method(self, scope: &Scope) -> Self::IntoIter {
self.__expand_iter_mut_method(scope)
}
}