hypershell_tokio_components/providers/
out.rs1use core::marker::PhantomData;
2
3use cgp::extra::handler::{Handler, HandlerComponent};
4use cgp::prelude::*;
5use hypershell_components::dsl::StreamToStdout;
6use tokio::io::{AsyncRead, copy};
7
8#[cgp_new_provider]
9impl<Context, Input> Handler<Context, StreamToStdout, Input> for HandleStreamToStdout
10where
11 Context: CanRaiseAsyncError<std::io::Error>,
12 Input: Send + AsyncRead + Unpin,
13{
14 type Output = ();
15
16 async fn handle(
17 _context: &Context,
18 _tag: PhantomData<StreamToStdout>,
19 mut input: Input,
20 ) -> Result<(), Context::Error> {
21 let mut stdout = tokio::io::stdout();
22
23 copy(&mut input, &mut stdout)
24 .await
25 .map_err(Context::raise_error)?;
26
27 Ok(())
28 }
29}