let iters: Vec<_> = range
.clone()
.map(test_source)
- //.map(|s| s.into_boxed())
+ .map(|s| s.into_boxed())
.collect();
let s = Merger::from(iters);
let mut v = Vec::<u8>::new();
{
FilterSource::new(self, filter_func)
}
+
+ fn into_boxed(self) -> Box<dyn DynSource<Item = Self::Item>>
+ where
+ Self: Sized + 'static,
+ {
+ // Inner Box satisfied DynSource, outer Box required for an owned DynSource trait object.
+ Box::new(Box::new(self))
+ }
+}
+
+// A dyn-compatible variant of Source generating boxed SeekableIters. Necessary to create
+// heterogeneous collections of sources.
+pub trait DynSource {
+ type Item;
+
+ fn iter(&self) -> Box<dyn SeekableIter<Item = Self::Item> + '_>;
}
-impl<S: Source + ?Sized> Source for Box<S> {
+impl<S: Source + ?Sized> DynSource for Box<S> {
type Item = S::Item;
- fn iter(&self) -> impl SeekableIter<Item = Self::Item> {
+
+ fn iter(&self) -> Box<dyn SeekableIter<Item = Self::Item> + '_> {
Box::new(self.as_ref().iter())
}
}
+impl<D: DynSource + ?Sized> Source for D {
+ type Item = D::Item;
+ fn iter(&self) -> impl SeekableIter<Item = Self::Item> {
+ DynSource::iter(self)
+ }
+}
+
pub struct VecIter<'a> {
index: usize,
vec: &'a Vec<Entry>,