glsl_layout/
uniform.rs

1/// Special marker trait implemented only for `std140` types.
2///
3/// # Safety
4/// The type must not have any padding bytes
5pub unsafe trait Std140: Sized + Uniform<Std140 = Self> {
6    /// Convert to bytes-slice.
7    fn as_raw(&self) -> &[u8] {
8        use std::{mem::size_of, slice::from_raw_parts};
9        unsafe { from_raw_parts(self as *const Self as *const u8, size_of::<Self>()) }
10    }
11}
12
13/// Structure to transform data from rust's structure to the raw data ready to upload to UBO.
14/// Users should prefer to use `derive(Uniform)` instead of implementing this manually.
15pub trait Uniform: Copy {
16    /// ZST that enforces alignment required for this type.
17    type Align: Copy + Default;
18
19    /// Type that contain same data with memory layout matching glsl's `layout(std140)`.
20    type Std140: Std140;
21
22    /// Get aligned data from structure.
23    fn std140(&self) -> Self::Std140;
24}