flense 0.2.2

Purpose-oriented lensing
Documentation
use std::mem;

use flense::prelude::*;

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

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

#[repr(C)]
struct S {
    pos: [f32; 3],
    col: [f32; 3],
}

// SAFETY: Position is at offset 0, size 12
unsafe impl Adapter<Position> for S {
    const OFFSET: usize = mem::offset_of!(Self, pos);
}
// SAFETY: Color is at offset 12, size 12 - disjoint from Position
unsafe impl Adapter<Color> for S {
    const OFFSET: usize = mem::offset_of!(Self, col);
}

fn main() {
    let mut data = [S {
        pos: [0.0; 3],
        col: [0.0; 3],
    }];
    let lens: LensSliceMut<'_, (Position, Color)> = (&mut data[..]).lens_slice_mut();
    let (mut lhs, _rhs) = lens.split::<(Position,), _>();

    let mut l = lhs.get_all_mut(0).unwrap();
    let x: &mut [f32; 3] = l.as_mut::<Color, _>();
    *x = [1.0, 2.0, 3.0];
}