Trait VecAlignment

Source
pub unsafe trait VecAlignment:
    Sized
    + 'static
    + Send
    + Sync {
    type Alignment<const N: usize, T: Scalar>: AlignTrait
       where Usize<N>: VecLen;

    const IS_ALIGNED: bool;
}
Expand description

Sealed marker trait.

All ggmath types are generic over the marker type A: VecAlignment.

The value of A decides whether or not the vector is aligned for SIMD (see https://doc.rust-lang.org/reference/type-layout.html).

This marker trait is implemented by VecAligned and VecPacked.

VecAligned means that the vector is aligned for SIMD. This does not promise a specific alignment. The alignment is selected by the Scalar implementation, to be whatever is most efficient for the target platform’s SIMD.

VecPacked means that the vector is not aligned for SIMD, and is identical in memory to [T; N].

Implementing this trait for a custom type is straight up undefined behavior.

Required Associated Constants§

Source

const IS_ALIGNED: bool

Is used internally by Vector to know if the vector is aligned in a generic function.

Required Associated Types§

Source

type Alignment<const N: usize, T: Scalar>: AlignTrait where Usize<N>: VecLen

Is used to “redirect” the vector to its alignment marker-type through this pattern:

use ggmath::AlignTrait;

trait VecAlignment {
    type Alignment<const N: usize, T: Scalar>: AlignTrait;
}

trait VecLen {
    type Alignment<T: Scalar>: AlignTrait;
}

trait Scalar {
    type Vec2Alignment: AlignTrait;
    type Vec3Alignment: AlignTrait;
    type Vec4Alignment: AlignTrait;
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl VecAlignment for VecAligned

Source§

const IS_ALIGNED: bool = true

Source§

type Alignment<const N: usize, T: Scalar> = <Usize<N> as VecLen>::Alignment<T> where Usize<N>: VecLen

Source§

impl VecAlignment for VecPacked

Source§

const IS_ALIGNED: bool = false

Source§

type Alignment<const N: usize, T: Scalar> = Align<1> where Usize<N>: VecLen