wachter_storage 0.1.0

Some storage utilities developed for the Wachter game engine
Documentation
use std::alloc::Layout;

/// A flat, type-erased data storage
///
/// Our version of "just pack these bytes together, trust me with their shape, and return them
/// later."
pub struct BlobVec {
    // Number of elements I have in memory.
    elems: usize,
    // Number of elements I can fit without reallocating.
    capacity: usize,
    // Memory layout of the type. Can be derived from the type.
    layout: Layout,
    // TODO replace with a pointer to memory
    data: Vec<u8>,
}

impl BlobVec {
    pub fn new(layout: Layout) -> Self {
        Self {
            elems: 0,
            capacity: 0,
            data: Vec::new(),
            layout,
        }
    }

    pub fn capacity(&self) -> usize {
        self.capacity
    }
    pub fn size(&self) -> usize {
        self.elems
    }

    pub fn push<T: Sized>(&mut self, data: T) {
        std::mem::
        self.data.append(data);
        self.elems += 1;
    }

    pub fn get<T>(&self, idx: usize) -> &T {
        // TODO this is horribly hacky, I should really read what layout is and does.
        let size = self.layout.size();

        let data = self.data.as_slice()[idx * size] 
    }
}

#[cfg(test)]
mod tests {
    use super::BlobVec;

    #[test]
    fn test_empty_on_init() {
        let layout  = std::alloc::Layout::for_value(&8u8);
        let v: BlobVec = BlobVec::new(layout);
        assert_eq!(v.size(), 0);
        assert_eq!(v.capacity(), 0);
    }
    #[test]
    fn test_insertion_u8() {
        let layout  = std::alloc::Layout::for_value(&8u8);
        let v: BlobVec = BlobVec::new(layout);
        v.push()
    }

    #[derive(Eq, PartialEq)]
    struct Point {
        x: f32,
        y: f32,
    }
    #[test]
    fn test_insertion_struct() {
        let layout  = std::alloc::Layout::for_value(&8u8);
        let v: BlobVec = BlobVec::new(layout);
        assert_eq!(v.size(), 0);
        assert_eq!(v.capacity(), 0);
    }

}