polylane 0.14.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::ValidLayout;
use crate::mask::{Mask, MaskLayout};

use core::array;
use core::iter::FusedIterator;

/// An owning iterator of a SIMD mask.
#[must_use]
#[derive(Clone, Debug)]
pub struct IntoIter<const N: usize> {
	iter: array::IntoIter<bool, N>,
}

impl<const N: usize> IntoIter<N> {
	/// Constructs a new, owning iterator of a SIMD mask.
	#[inline]
	pub(crate) fn new(mask: Mask<N>) -> Self
	where
		MaskLayout<N>: ValidLayout,
	{
		let iter = mask.to_array().into_iter();

		Self { iter }
	}
}

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

impl<const N: usize> ExactSizeIterator for IntoIter<N> {}

impl<const N: usize> FusedIterator for IntoIter<N> {}

impl<const N: usize> Iterator for IntoIter<N> {
	type Item = bool;

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

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