arta_async_std/process/
outputs.rs1use cfg_if::cfg_if;
2use futures::{AsyncRead, AsyncWrite};
3use std::{
4 pin::Pin,
5 task::{Context, Poll},
6};
7
8pub struct AsyncStdStdin<'a> {
10 pub(super) inner: &'a mut async_std::process::ChildStdin,
11}
12
13pub struct AsyncStdStdout<'a> {
15 pub(super) inner: &'a mut async_std::process::ChildStdout,
16}
17
18pub struct AsyncStdStderr<'a> {
20 pub(super) inner: &'a mut async_std::process::ChildStderr,
21}
22
23impl AsyncWrite for AsyncStdStdin<'_> {
24 fn poll_write(
25 mut self: Pin<&mut Self>,
26 cx: &mut Context<'_>,
27 buf: &[u8],
28 ) -> Poll<std::io::Result<usize>> {
29 async_std::io::Write::poll_write(Pin::new(self.inner), cx, buf)
30 }
31
32 fn poll_write_vectored(
33 mut self: Pin<&mut Self>,
34 cx: &mut Context<'_>,
35 bufs: &[std::io::IoSlice<'_>],
36 ) -> Poll<std::io::Result<usize>> {
37 async_std::io::Write::poll_write_vectored(Pin::new(self.inner), cx, bufs)
38 }
39
40 fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
41 async_std::io::Write::poll_flush(Pin::new(self.inner), cx)
42 }
43
44 fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
45 async_std::io::Write::poll_close(Pin::new(self.inner), cx)
46 }
47}
48
49impl AsyncRead for AsyncStdStdout<'_> {
50 fn poll_read(
51 mut self: Pin<&mut Self>,
52 cx: &mut Context<'_>,
53 buf: &mut [u8],
54 ) -> Poll<std::io::Result<usize>> {
55 async_std::io::Read::poll_read(Pin::new(self.inner), cx, buf)
56 }
57
58 fn poll_read_vectored(
59 mut self: Pin<&mut Self>,
60 cx: &mut Context<'_>,
61 bufs: &mut [std::io::IoSliceMut<'_>],
62 ) -> Poll<std::io::Result<usize>> {
63 async_std::io::Read::poll_read_vectored(Pin::new(self.inner), cx, bufs)
64 }
65}
66
67impl AsyncRead for AsyncStdStderr<'_> {
68 fn poll_read(
69 mut self: Pin<&mut Self>,
70 cx: &mut Context<'_>,
71 buf: &mut [u8],
72 ) -> Poll<std::io::Result<usize>> {
73 async_std::io::Read::poll_read(Pin::new(self.inner), cx, buf)
74 }
75
76 fn poll_read_vectored(
77 mut self: Pin<&mut Self>,
78 cx: &mut Context<'_>,
79 bufs: &mut [std::io::IoSliceMut<'_>],
80 ) -> Poll<std::io::Result<usize>> {
81 async_std::io::Read::poll_read_vectored(Pin::new(self.inner), cx, bufs)
82 }
83}
84
85cfg_if! {
86 if #[cfg(windows)] {
87 impl std::os::windows::io::AsRawHandle for AsyncStdStdin<'_> {
88 fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
89 self.inner.as_raw_handle()
90 }
91 }
92
93 impl std::os::windows::io::AsRawHandle for AsyncStdStdout<'_> {
94 fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
95 self.inner.as_raw_handle()
96 }
97 }
98
99 impl std::os::windows::io::AsRawHandle for AsyncStdStderr<'_> {
100 fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
101 self.inner.as_raw_handle()
102 }
103 }
104
105 impl std::os::windows::io::AsHandle for AsyncStdStdin<'_> {
106 fn as_handle(&self) -> std::os::windows::io::BorrowedHandle<'_> {
107 let raw_handle = std::os::windows::io::AsRawHandle::as_raw_handle(self);
108 unsafe { std::os::windows::io::BorrowedHandle::borrow_raw(raw_handle) }
109 }
110 }
111
112 impl std::os::windows::io::AsHandle for TokioStdout<'_> {
113 fn as_handle(&self) -> std::os::windows::io::BorrowedHandle<'_> {
114 let raw_handle = std::os::windows::io::AsRawHandle::as_raw_handle(self);
115 unsafe { std::os::windows::io::BorrowedHandle::borrow_raw(raw_handle) }
116 }
117 }
118
119 impl std::os::windows::io::AsHandle for TokioStderr<'_> {
120 fn as_handle(&self) -> std::os::windows::io::BorrowedHandle<'_> {
121 let raw_handle = std::os::windows::io::AsRawHandle::as_raw_handle(self);
122 unsafe { std::os::windows::io::BorrowedHandle::borrow_raw(raw_handle) }
123 }
124 }
125 } else if #[cfg(any(unix, target_os = "wasi"))] {
126 impl std::os::fd::AsRawFd for AsyncStdStdin<'_> {
127 fn as_raw_fd(&self) -> std::os::unix::prelude::RawFd {
128 self.inner.as_raw_fd()
129 }
130 }
131
132 impl std::os::fd::AsRawFd for AsyncStdStdout<'_> {
133 fn as_raw_fd(&self) -> std::os::unix::prelude::RawFd {
134 self.inner.as_raw_fd()
135 }
136 }
137
138 impl std::os::fd::AsRawFd for AsyncStdStderr<'_> {
139 fn as_raw_fd(&self) -> std::os::unix::prelude::RawFd {
140 self.inner.as_raw_fd()
141 }
142 }
143
144 impl std::os::fd::AsFd for AsyncStdStdin<'_> {
145 fn as_fd(&self) -> std::os::unix::prelude::BorrowedFd<'_> {
146 let raw_fd = std::os::fd::AsRawFd::as_raw_fd(self);
147 unsafe { std::os::fd::BorrowedFd::borrow_raw(raw_fd) }
148 }
149 }
150
151 impl std::os::fd::AsFd for AsyncStdStdout<'_> {
152 fn as_fd(&self) -> std::os::unix::prelude::BorrowedFd<'_> {
153 let raw_fd = std::os::fd::AsRawFd::as_raw_fd(self);
154 unsafe { std::os::fd::BorrowedFd::borrow_raw(raw_fd) }
155 }
156 }
157
158 impl std::os::fd::AsFd for AsyncStdStderr<'_> {
159 fn as_fd(&self) -> std::os::unix::prelude::BorrowedFd<'_> {
160 let raw_fd = std::os::fd::AsRawFd::as_raw_fd(self);
161 unsafe { std::os::fd::BorrowedFd::borrow_raw(raw_fd) }
162 }
163 }
164 }
165}