polylane 0.15.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/>.

mod test;

mod r#impl;

use crate::ValidLayout;
use crate::mask::{Mask, MaskLayout};
use crate::simd::{Simd, SimdLayout, SimdScalar};

/// Denotes SIMD vector of constant pointers.
#[expect(clippy::wrong_self_convention)]
pub trait SimdConstPtr<T, const N: usize>: crate::ptr::seal::SimdConstPtr
where
	T: Sized,

	SimdLayout<*const T, N>: ValidLayout,

	SimdLayout<usize, N>: ValidLayout,
{
	/// See [`ptr::null`](core::ptr::null).
	#[must_use]
	fn null() -> Self;

	/// See [`ptr::dangling`](core::ptr::dangling).
	#[must_use]
	fn dangling() -> Self;

	/// See [`ptr::with_exposed_provenance`](core::ptr::with_exposed_provenance).
	#[must_use]
	fn with_exposed_provenance(addr: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	/// See [`ptr::without_provenance`](core::ptr::without_provenance).
	#[must_use]
	fn without_provenance(addr: Simd<usize, N>) -> Self;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::offset`](pointer::offset).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::offset`.")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn offset(self, count: Simd<isize, N>) -> Self
	where
		SimdLayout<isize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::byte_offset`](pointer::byte_offset).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::byte_offset`.")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn byte_offset(self, count: Simd<isize, N>) -> Self
	where
		SimdLayout<isize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::add`](pointer::add).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::add`.")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn add(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::byte_add`](pointer::byte_add).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::byte_add`.")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn byte_add(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::sub`](pointer::sub).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::sub`.")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn sub(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::byte_sub`](pointer::byte_sub).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::byte_sub`.")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn byte_sub(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::wrapping_offset`](pointer::wrapping_offset).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::wrapping_offset`.")]
	#[must_use]
	fn wrapping_offset(self, count: Simd<isize, N>) -> Self
	where
		SimdLayout<isize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::wrapping_byte_offset`](pointer::wrapping_byte_offset).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::wrapping_byte_offset`.")]
	#[must_use]
	fn wrapping_byte_offset(self, count: Simd<isize, N>) -> Self
	where
		SimdLayout<isize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::wrapping_add`](pointer::wrapping_add).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::wrapping_add`.")]
	#[must_use]
	fn wrapping_add(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::wrapping_byte_add`](pointer::wrapping_byte_add).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::wrapping_byte_add`.")]
	#[must_use]
	fn wrapping_byte_add(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::wrapping_sub`](pointer::wrapping_sub).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::wrapping_sub`.")]
	#[must_use]
	fn wrapping_sub(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::wrapping_byte_sub`](pointer::wrapping_byte_sub).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::wrapping_byte_sub`.")]
	#[must_use]
	fn wrapping_byte_sub(self, count: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::map_addr`](pointer::map_addr).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::map_addr`.")]
	#[must_use]
	fn map_addr<F>(self, op: F) -> Self
	where
		F: FnMut(usize) -> usize,

		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::read`](pointer::read).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See [`ptr::read`](core::ptr::read).")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn read(self) -> Simd<T, N>
	where
		T: SimdScalar,

		SimdLayout<T, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::read_volatile`](pointer::read_volatile).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See [`ptr::read_volatile`](core::ptr::read_volatile).")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn read_volatile(self) -> Simd<T, N>
	where
		T: SimdScalar,

		SimdLayout<T, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::read_unaligned`](pointer::read_unaligned).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See [`ptr::read_unaligned`](core::ptr::read_unaligned).")]
	#[expect(clippy::missing_safety_doc)]
	#[must_use]
	unsafe fn read_unaligned(self) -> Simd<T, N>
	where
		T: SimdScalar,

		SimdLayout<T, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::addr`](pointer::addr).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::addr`.")]
	#[must_use]
	fn addr(self) -> Simd<usize, N>
	where
		SimdLayout<usize,  N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::align_offset`](pointer::align_offset).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::align_offset`.")]
	#[must_use]
	fn align_offset(self, align: Simd<usize, N>) -> Simd<usize, N>
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::is_null`](pointer::is_null).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::is_null`.")]
	#[must_use]
	fn is_null(self) -> Mask<N>
	where
		MaskLayout<N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::is_aligned`](pointer::is_aligned).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::is_aligned`.")]
	#[must_use]
	fn is_aligned(self) -> Mask<N>
	where
		MaskLayout<N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::with_addr`](pointer::with_addr).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::with_addr`.")]
	#[must_use]
	fn with_addr(self, addr: Simd<usize, N>) -> Self
	where
		SimdLayout<usize, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::cast`](pointer::cast).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::cast`.")]
	#[must_use]
	fn cast<U>(self) -> Simd<*const U, N>
	where
		U: Sized,

		SimdLayout<*const U, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*con>::cast_mut`](pointer::cast).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::cast_mut`.")]
	#[must_use]
	fn cast_mut(self) -> Simd<*mut T, N>
	where
		SimdLayout<*mut T, N>: ValidLayout;

	#[cfg_attr(feature = "unstable_docs",      doc = "See [`<*const _>::expose_provenance`](pointer::expose_provenance).")]
	#[cfg_attr(not(feature = "unstable_docs"), doc = "See `<*const _>::expose_provenance`.")]
	#[must_use]
	fn expose_provenance(self) -> Simd<usize, N>
	where
		SimdLayout<usize, N>: ValidLayout;
}