erased-cells 0.1.1

Create to enable manipulation of heterogeneous values and buffers of Rust primitive numeric types
Documentation
use erased_cells::{BufferOps, CellBuffer, CellType, CellValue};

fn main() {
    // Fill a buffer with the `u8` numbers `0..=8`.
    let buf1 = CellBuffer::fill_via(9, |i| i as u8);

    // `u8` maps to `CellType::UInt8`
    assert_eq!(buf1.cell_type(), CellType::UInt8);

    // A fetching values maintains its CellType through a CellValue.
    let val: CellValue = buf1.get(3);
    assert_eq!(val, CellValue::UInt8(3));
    let (min, max): (CellValue, CellValue) = buf1.min_max();
    assert_eq!((min, max), (CellValue::UInt8(0), CellValue::UInt8(8)));

    // Basic math ops work on CellValues. Primitives can be converted to CellValues with `into`.
    // Math ops coerce to floating point values.
    assert_eq!(((max - min + 1) / 2), 4.5.into());

    // Fill another buffer with the `f32` numbers `8..=0`.
    let buf2 = CellBuffer::fill_via(9, |i| 8f32 - i as f32);
    assert_eq!(buf2.cell_type(), CellType::Float32);
    assert_eq!(
        buf2.min_max(),
        (CellValue::Float32(0.0), CellValue::Float32(8.0))
    );

    // Basic math ops also work on CellBuffers, applied element-wise.
    let diff = buf2 - buf1;
    assert_eq!(diff.min_max(), ((-8).into(), 8.into()));
}