soa_rs/
soars.rs

1use crate::{AsSoaRef, SoaDeref, SoaRaw};
2
3#[diagnostic::on_unimplemented(
4    label = "SOA type",
5    note = "The Soars trait is required for SOA compatibility"
6)]
7/// Provides [`Soa`] compatibility.
8///
9/// # Safety
10///
11/// [`Soars::Deref`] must be `#[repr(transparent)]` with [`Slice<Self::Raw>`].
12/// This trait should be derived using the derive macro.
13///
14/// [`Slice<Self::Raw>`]: crate::Slice
15/// [`Soa`]: crate::Soa
16pub unsafe trait Soars: AsSoaRef<Item = Self> {
17    /// Implements internal, unsafe, low-level routines used by [`Soa`]
18    ///
19    /// [`Soa`]: crate::Soa
20    type Raw: SoaRaw<Item = Self>;
21
22    /// [`Slice`] dereferences to this type to provide getters for the individual
23    /// fields as slices.
24    ///
25    /// [`Slice`]: crate::Slice
26    type Deref: ?Sized + SoaDeref<Item = Self>;
27
28    /// A reference to an element of a [`Slice`].
29    ///
30    /// For each field with type `T`, this type has a field with type `&T`.
31    ///
32    /// [`Slice`]: crate::Slice
33    type Ref<'a>: AsSoaRef<Item = Self>
34    where
35        Self: 'a;
36
37    /// A reference to an element of a [`Slice`].
38    ///
39    /// For each field with type `T`, this type has a field with type `&mut T`.
40    ///
41    /// [`Slice`]: crate::Slice
42    type RefMut<'a>: AsSoaRef<Item = Self>
43    where
44        Self: 'a;
45
46    /// The slices that make up a [`Slice`].
47    ///
48    /// For each field with type `T`, this type has a field with type `&[T]`.
49    ///
50    /// [`Slice`]: crate::Slice
51    type Slices<'a>
52    where
53        Self: 'a;
54
55    /// The mutable slices that make up a [`Slice`].
56    ///
57    /// For each field with type `T`, this type has a field with type `&mut [T]`.
58    ///
59    /// [`Slice`]: crate::Slice
60    type SlicesMut<'a>
61    where
62        Self: 'a;
63}