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