}
}
+struct WrapSource<'a, S: Source<'a> + Ranges<'a>>(S, PhantomData<&'a S>);
+impl<'a, S: Source<'a> + Ranges<'a>> Source<'a> for WrapSource<'a, S> {
+ type It = Box<dyn Iter + 'a>;
+ fn iter(&'a self) -> Self::It {
+ Box::new(self.0.iter())
+ }
+}
+impl<'a, S: Source<'a> + Ranges<'a>> Ranges<'a> for WrapSource<'a, S> {
+ type Get = Box<dyn Iter + 'a>;
+ type Prefix = Box<dyn Iter + 'a>;
+ type Range = Box<dyn Iter + 'a>;
+
+ fn get(&'a self, key: &[u8]) -> Self::Get {
+ Box::new(self.0.get(key))
+ }
+ fn get_prefix(&'a self, prefix: &[u8]) -> Self::Prefix {
+ Box::new(self.0.get_prefix(prefix))
+ }
+ fn get_range(&'a self, start: &[u8], end: &[u8]) -> Self::Range {
+ Box::new(self.0.get_range(start, end))
+ }
+}
+
+struct GenericSource<'a>(
+ Box<dyn Source<'a, It = Box<dyn Iter + 'a>> + 'a>,
+ PhantomData<&'a u8>,
+);
+impl<'a> GenericSource<'a> {
+ fn from<S: Source<'a> + Ranges<'a> + 'a>(source: S) -> Self {
+ GenericSource(Box::new(WrapSource(source, PhantomData)), PhantomData)
+ }
+}
+
+impl<'a> Source<'a> for GenericSource<'a> {
+ type It = Box<dyn Iter + 'a>;
+ fn iter(&'a self) -> Self::It {
+ self.0.iter()
+ }
+}
+impl<'a> DefaultRanges for GenericSource<'a> {}
+
#[cfg(test)]
pub mod test {
use super::{DefaultRanges, Entry, Iter, Ranges, Source};