use std::fmt::Debug;
pub trait StorageBuffer: Clone + Debug + Default
{
type Element: Clone + Debug + Default;
fn read(&self, idx: u64) -> &Self::Element;
fn update<F: FnMut(&mut Self::Element)>(&mut self, idx: u64, update: F);
fn append(&mut self, value: Self::Element);
fn discard(&mut self, idx: u64) -> Self::Element;
fn filter<F: FnMut(&Self::Element) -> bool>(&mut self, keep: F);
fn len(&self) -> usize;
fn iter_ref(&self) -> impl Iterator<Item = &Self::Element>;
}
impl<T: Default + Clone + Debug> StorageBuffer for Vec<T>
{
type Element = T;
fn read(&self, idx: u64) -> &Self::Element { &self[idx as usize] }
fn update<F: FnMut(&mut Self::Element)>(&mut self, idx: u64, mut update: F)
{
update(&mut self[idx as usize])
}
fn append(&mut self, value: Self::Element) { self.push(value) }
fn discard(&mut self, idx: u64) -> Self::Element { self.remove(idx as usize) }
fn filter<F: FnMut(&Self::Element) -> bool>(&mut self, keep: F) { self.retain(keep) }
fn len(&self) -> usize { self.len() }
fn iter_ref(&self) -> impl Iterator<Item = &Self::Element> { self.iter() }
}
impl StorageBuffer for ()
{
type Element = ();
fn read(&self, _idx: u64) -> &Self::Element { self }
fn update<F: FnMut(&mut Self::Element)>(&mut self, _idx: u64, mut _update: F) {}
fn append(&mut self, _value: Self::Element) {}
fn discard(&mut self, _idx: u64) -> Self::Element {}
fn filter<F: FnMut(&Self::Element) -> bool>(&mut self, _f: F) {}
fn iter_ref(&self) -> impl Iterator<Item = &Self::Element> { std::iter::empty() }
fn len(&self) -> usize { 0 }
}
pub trait MeshStorage
{
type VertStorage: StorageBuffer;
type EdgeStorage: StorageBuffer;
type FaceStorage: StorageBuffer;
}
pub type VertData<M> = <<M as MeshStorage>::VertStorage as StorageBuffer>::Element;
pub type EdgeData<M> = <<M as MeshStorage>::EdgeStorage as StorageBuffer>::Element;
pub type FaceData<M> = <<M as MeshStorage>::FaceStorage as StorageBuffer>::Element;
impl<V, E, F> MeshStorage for (V, E, F)
where
V: StorageBuffer,
E: StorageBuffer,
F: StorageBuffer,
{
type EdgeStorage = E;
type FaceStorage = F;
type VertStorage = V;
}