use crate::{ReadableVec, VecIndex, VecValue};
pub trait ReadableOptionVec<I: VecIndex, T: VecValue + Default> {
fn collect_or_default(&self) -> Vec<T>;
fn collect_one_flat(&self, index: I) -> Option<T>;
}
impl<V, I, T> ReadableOptionVec<I, T> for V
where
V: ReadableVec<I, Option<T>> + Sized,
I: VecIndex,
T: VecValue + Default,
{
fn collect_or_default(&self) -> Vec<T> {
self.fold(Vec::with_capacity(self.len()), |mut v, opt| {
v.push(opt.unwrap_or_default());
v
})
}
fn collect_one_flat(&self, index: I) -> Option<T> {
self.collect_one(index).flatten()
}
}