polylane 0.6.0

Portable and versatile SIMD.
Documentation
// Copyright 2025 Gabriel Bjørnager Jensen.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, you
// can obtain one at:
// <https://mozilla.org/MPL/2.0/>.

use crate::simd::SimdElement;

use core::iter::FusedIterator;
use core::slice;

/// A borrowing iterator of a SIMD vector.
#[derive(Clone, Debug)]
pub struct Iter<'a, T: SimdElement, const N: usize> {
	iter: slice::Iter<'a, T>,
}

impl<'a, T: SimdElement, const N: usize> Iter<'a, T, N> {
	/// Constructs a new, borrowing iterator of a SIMD vector.
	#[inline]
	#[must_use]
	pub(crate) fn new(data: &'a [T; N]) -> Self {
		Self { iter: data.iter() }
	}
}

impl<T: SimdElement, const N: usize> DoubleEndedIterator for Iter<'_, T, N> {
	#[inline(always)]
	fn next_back(&mut self) -> Option<Self::Item> {
		self.iter.next_back()
	}
}

impl<T: SimdElement, const N: usize> ExactSizeIterator for Iter<'_, T, N> { }

impl<T: SimdElement, const N: usize> FusedIterator for Iter<'_, T, N> { }

impl<'a, T: SimdElement, const N: usize> Iterator for Iter<'a, T, N> {
	type Item = &'a T;

	#[inline(always)]
	fn next(&mut self) -> Option<Self::Item> {
		self.iter.next()
	}

	#[inline(always)]
	fn size_hint(&self) -> (usize, Option<usize>) {
		self.iter.size_hint()
	}
}