polylane 0.10.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::SimdScalar;

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

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

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

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

impl<T: SimdScalar, const N: usize> ExactSizeIterator for IterMut<'_, T, N> {}

impl<T: SimdScalar, const N: usize> FusedIterator for IterMut<'_, T, N> {}

impl<'a, T: SimdScalar, const N: usize> Iterator for IterMut<'a, T, N> {
	type Item = &'a mut T;

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

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