flense 0.2.2

Purpose-oriented lensing
Documentation
//! Common shared definitions for tests.

#![allow(dead_code, missing_docs)]

use std::mem;

use flense::prelude::*;

pub enum Position {}
impl Field for Position {
    type Type = [f32; 3];
}

pub enum Color {}
impl Field for Color {
    type Type = [f32; 3];
}

pub enum Normal {}
impl Field for Normal {
    type Type = [u8; 2];
}

pub enum Other {}
impl Field for Other {
    type Type = u64;
}

// SAFETY: Reflexive implementation of Adapter
unsafe impl Adapter<Position> for [f32; 3] {
    const OFFSET: usize = 0;
}
// SAFETY: Reflexive implementation of Adapter
unsafe impl Adapter<Color> for [f32; 3] {
    const OFFSET: usize = 0;
}
// SAFETY: Reflexive implementation of Adapter
unsafe impl Adapter<Normal> for [u8; 2] {
    const OFFSET: usize = 0;
}
// SAFETY: Reflexive implementation of Adapter
unsafe impl Adapter<Other> for u64 {
    const OFFSET: usize = 0;
}

#[derive(Default, Clone, Copy)]
pub struct Vertex {
    pub position: [f32; 3],
    pub color: [f32; 3],
    pub normal: [u8; 2],
    pub other: u64,
}

// SAFETY: Correct Adapter implementation using offset_of!
unsafe impl Adapter<Position> for Vertex {
    const OFFSET: usize = mem::offset_of!(Self, position);
}
// SAFETY: Correct Adapter implementation using offset_of!
unsafe impl Adapter<Color> for Vertex {
    const OFFSET: usize = mem::offset_of!(Self, color);
}
// SAFETY: Correct Adapter implementation using offset_of!
unsafe impl Adapter<Normal> for Vertex {
    const OFFSET: usize = mem::offset_of!(Self, normal);
}
// SAFETY: Correct Adapter implementation using offset_of!
unsafe impl Adapter<Other> for Vertex {
    const OFFSET: usize = mem::offset_of!(Self, other);
}