1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21

use std::io::Read;

use std::pin::Pin;


use futures::{Stream, StreamExt};


use crate::layers::domain::reader_factory::{ReaderFactory, ReaderContext};

pub fn reader_stream<Reader: Read + 'static>(
    reader_factory: Box<dyn ReaderFactory<Reader>>,
    file_path_stream: Pin<Box<dyn Stream<Item=Result<String, String>>>>) -> Pin<Box<dyn Stream<Item=Result<ReaderContext<Reader>, String>>>> {
    Box::pin(file_path_stream.map(move |path| {
        match path {
            Err(e) => Err(e),
            Ok(path) => reader_factory.make_reader(path)
        }
    }))
}