brush_core/sys/unix/
async_pipe.rs1use std::io;
4use std::os::unix::io::OwnedFd;
5
6use tokio::net::unix::pipe;
7
8pub(crate) struct AsyncPipeReader(pipe::Receiver);
9
10impl AsyncPipeReader {
11 pub(crate) fn new(reader: std::io::PipeReader) -> io::Result<Self> {
12 Ok(Self(pipe::Receiver::from_file(std::fs::File::from(
13 OwnedFd::from(reader),
14 ))?))
15 }
16
17 pub(crate) async fn read_to_string(&mut self) -> io::Result<String> {
18 use tokio::io::AsyncReadExt;
19 let mut s = String::new();
20 self.0.read_to_string(&mut s).await?;
21 Ok(s)
22 }
23}