#[derive(Soapy)]
{
// Attributes available to this derive:
#[align]
#[soa_derive]
}
Expand description
Derive macro for the Soapy trait.
Deriving Soapy for some struct Foo will create the following additional
structs:
| Struct | Field type | Use |
|---|---|---|
FooSoaRaw | *mut T | Low-level, unsafe memory handling for SoA |
FooRef | &T | SoA element reference |
FooRefMut | &mut T | Mutable SoA element reference |
FooSlices | &[T] | SoA fields |
FooSlicesMut | &mut [T] | Mutable SoA fields |
FooArray | [T; N] | const-compatible SoA |
FooDeref | SoA Deref target, provides slice getters |
The Soapy trait implementation for Foo references these as associated
types. AsSoaRef is also implemented for Foo, FooRef, and FooRefMut.
§Derive for generated types
The soa_derive attribute can be used to derive traits for the generated
types. In the example, Debug and PartialEq will be implemented for
FooRef, FooRefMut, FooSlices, FooSlicesMut, and FooArray.
#[derive(Soapy)]
#[soa_derive(Debug, PartialEq)]
struct Foo(u8);
assert_eq!(FooRef(&10), FooRef(&10));§Alignment
Individual fields can be tagged with the align attribute to raise their
alignment. The slice for that field will start at a multiple of the
requested alignment if it is greater than or equal to the alignment of the
field’s type. This can be useful for vector operations.
struct Foo(#[align(8)] u8);