hermes_async_runtime_components/stream/impls/
map.rs

1use alloc::boxed::Box;
2
3use cgp::prelude::*;
4use futures_util::stream::StreamExt;
5use hermes_runtime_components::traits::stream::StreamMapper;
6
7use crate::stream::traits::boxed::HasBoxedStreamType;
8
9pub struct BoxedStreamMapper;
10
11impl<Runtime> StreamMapper<Runtime> for BoxedStreamMapper
12where
13    Runtime: HasBoxedStreamType,
14{
15    fn map_stream<T, U, M>(stream: Runtime::Stream<T>, mapper: M) -> Runtime::Stream<U>
16    where
17        T: Async,
18        U: Async,
19        M: Fn(T) -> U + Async,
20    {
21        let mapped = Runtime::to_boxed_stream(stream).map(mapper);
22
23        Runtime::from_boxed_stream(Box::pin(mapped))
24    }
25}