use crate::inner::Inner;
pub struct MultiReaders<T> {
pub(crate) inner: Vec<Inner<T>>,
pub(crate) len: u64,
pub(crate) pos: usize,
#[cfg(feature = "async")]
pub(crate) buf: Vec<u8>,
#[cfg(feature = "async")]
pub(crate) filled: usize,
}
impl<T> MultiReaders<T> {
pub fn new<I: Iterator<Item = T> + 'static>(values: I) -> Self {
Self {
inner: values.map(Inner::new).collect(),
pos: 0,
len: 0,
#[cfg(feature = "async")]
buf: Vec::new(),
#[cfg(feature = "async")]
filled: 0,
}
}
}
impl<T: IntoIterator<Item = E>, E> MultiReaders<T> {
pub fn flatten(self) -> MultiReaders<E> {
if self.pos != 0 {
panic!("Only allowed to be called during initialization!")
}
let inner = self
.inner
.into_iter()
.flat_map(Inner::inner)
.map(Inner::new)
.collect();
MultiReaders {
inner,
pos: 0,
len: 0,
#[cfg(feature = "async")]
buf: Vec::new(),
#[cfg(feature = "async")]
filled: 0,
}
}
}