|
1 | 1 | use crate::io;
|
2 |
| -use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner}; |
| 2 | +use crate::sys::pipe::{AnonPipe, anon_pipe}; |
| 3 | +use crate::sys_common::{AsInner, FromInner, IntoInner}; |
3 | 4 |
|
4 | 5 | /// Create an anonymous pipe.
|
5 | 6 | ///
|
@@ -66,18 +67,23 @@ use crate::sys::anonymous_pipe::{AnonPipe, pipe as pipe_inner};
|
66 | 67 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
67 | 68 | #[inline]
|
68 | 69 | pub fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
|
69 |
| - pipe_inner().map(|(reader, writer)| (PipeReader(reader), PipeWriter(writer))) |
| 70 | + anon_pipe() |
| 71 | + .map(|(reader, writer)| (PipeReader::from_inner(reader), PipeWriter::from_inner(writer))) |
70 | 72 | }
|
71 | 73 |
|
72 | 74 | /// Read end of an anonymous pipe.
|
73 | 75 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
74 | 76 | #[derive(Debug)]
|
75 |
| -pub struct PipeReader(pub(crate) AnonPipe); |
| 77 | +pub struct PipeReader { |
| 78 | + inner: AnonPipe, |
| 79 | +} |
76 | 80 |
|
77 | 81 | /// Write end of an anonymous pipe.
|
78 | 82 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
79 | 83 | #[derive(Debug)]
|
80 |
| -pub struct PipeWriter(pub(crate) AnonPipe); |
| 84 | +pub struct PipeWriter { |
| 85 | + inner: AnonPipe, |
| 86 | +} |
81 | 87 |
|
82 | 88 | impl PipeReader {
|
83 | 89 | /// Create a new [`PipeReader`] instance that shares the same underlying file description.
|
@@ -131,7 +137,7 @@ impl PipeReader {
|
131 | 137 | /// ```
|
132 | 138 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
133 | 139 | pub fn try_clone(&self) -> io::Result<Self> {
|
134 |
| - self.0.try_clone().map(Self) |
| 140 | + self.as_inner().try_clone().map(Self::from_inner) |
135 | 141 | }
|
136 | 142 | }
|
137 | 143 |
|
@@ -167,82 +173,116 @@ impl PipeWriter {
|
167 | 173 | /// ```
|
168 | 174 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
169 | 175 | pub fn try_clone(&self) -> io::Result<Self> {
|
170 |
| - self.0.try_clone().map(Self) |
| 176 | + self.as_inner().try_clone().map(Self::from_inner) |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +impl AsInner<AnonPipe> for PipeReader { |
| 181 | + #[inline] |
| 182 | + fn as_inner(&self) -> &AnonPipe { |
| 183 | + &self.inner |
| 184 | + } |
| 185 | +} |
| 186 | +impl FromInner<AnonPipe> for PipeReader { |
| 187 | + fn from_inner(pipe: AnonPipe) -> PipeReader { |
| 188 | + PipeReader { inner: pipe } |
| 189 | + } |
| 190 | +} |
| 191 | +impl IntoInner<AnonPipe> for PipeReader { |
| 192 | + fn into_inner(self) -> AnonPipe { |
| 193 | + self.inner |
| 194 | + } |
| 195 | +} |
| 196 | + |
| 197 | +impl AsInner<AnonPipe> for PipeWriter { |
| 198 | + #[inline] |
| 199 | + fn as_inner(&self) -> &AnonPipe { |
| 200 | + &self.inner |
| 201 | + } |
| 202 | +} |
| 203 | +impl FromInner<AnonPipe> for PipeWriter { |
| 204 | + fn from_inner(pipe: AnonPipe) -> PipeWriter { |
| 205 | + PipeWriter { inner: pipe } |
| 206 | + } |
| 207 | +} |
| 208 | +impl IntoInner<AnonPipe> for PipeWriter { |
| 209 | + fn into_inner(self) -> AnonPipe { |
| 210 | + self.inner |
171 | 211 | }
|
172 | 212 | }
|
173 | 213 |
|
174 | 214 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
175 | 215 | impl io::Read for &PipeReader {
|
176 | 216 | fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
177 |
| - self.0.read(buf) |
| 217 | + self.as_inner().read(buf) |
178 | 218 | }
|
179 | 219 | fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
|
180 |
| - self.0.read_vectored(bufs) |
| 220 | + self.as_inner().read_vectored(bufs) |
181 | 221 | }
|
182 | 222 | #[inline]
|
183 | 223 | fn is_read_vectored(&self) -> bool {
|
184 |
| - self.0.is_read_vectored() |
| 224 | + self.as_inner().is_read_vectored() |
185 | 225 | }
|
186 | 226 | fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
187 |
| - self.0.read_to_end(buf) |
| 227 | + self.as_inner().read_to_end(buf) |
188 | 228 | }
|
189 | 229 | fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
|
190 |
| - self.0.read_buf(buf) |
| 230 | + self.as_inner().read_buf(buf) |
191 | 231 | }
|
192 | 232 | }
|
193 | 233 |
|
194 | 234 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
195 | 235 | impl io::Read for PipeReader {
|
196 | 236 | fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
197 |
| - self.0.read(buf) |
| 237 | + self.as_inner().read(buf) |
198 | 238 | }
|
199 | 239 | fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
|
200 |
| - self.0.read_vectored(bufs) |
| 240 | + self.as_inner().read_vectored(bufs) |
201 | 241 | }
|
202 | 242 | #[inline]
|
203 | 243 | fn is_read_vectored(&self) -> bool {
|
204 |
| - self.0.is_read_vectored() |
| 244 | + self.as_inner().is_read_vectored() |
205 | 245 | }
|
206 | 246 | fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
207 |
| - self.0.read_to_end(buf) |
| 247 | + self.as_inner().read_to_end(buf) |
208 | 248 | }
|
209 | 249 | fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
|
210 |
| - self.0.read_buf(buf) |
| 250 | + self.as_inner().read_buf(buf) |
211 | 251 | }
|
212 | 252 | }
|
213 | 253 |
|
214 | 254 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
215 | 255 | impl io::Write for &PipeWriter {
|
216 | 256 | fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
217 |
| - self.0.write(buf) |
| 257 | + self.as_inner().write(buf) |
218 | 258 | }
|
219 | 259 | #[inline]
|
220 | 260 | fn flush(&mut self) -> io::Result<()> {
|
221 | 261 | Ok(())
|
222 | 262 | }
|
223 | 263 | fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
|
224 |
| - self.0.write_vectored(bufs) |
| 264 | + self.as_inner().write_vectored(bufs) |
225 | 265 | }
|
226 | 266 | #[inline]
|
227 | 267 | fn is_write_vectored(&self) -> bool {
|
228 |
| - self.0.is_write_vectored() |
| 268 | + self.as_inner().is_write_vectored() |
229 | 269 | }
|
230 | 270 | }
|
231 | 271 |
|
232 | 272 | #[stable(feature = "anonymous_pipe", since = "CURRENT_RUSTC_VERSION")]
|
233 | 273 | impl io::Write for PipeWriter {
|
234 | 274 | fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
235 |
| - self.0.write(buf) |
| 275 | + self.as_inner().write(buf) |
236 | 276 | }
|
237 | 277 | #[inline]
|
238 | 278 | fn flush(&mut self) -> io::Result<()> {
|
239 | 279 | Ok(())
|
240 | 280 | }
|
241 | 281 | fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
|
242 |
| - self.0.write_vectored(bufs) |
| 282 | + self.as_inner().write_vectored(bufs) |
243 | 283 | }
|
244 | 284 | #[inline]
|
245 | 285 | fn is_write_vectored(&self) -> bool {
|
246 |
| - self.0.is_write_vectored() |
| 286 | + self.as_inner().is_write_vectored() |
247 | 287 | }
|
248 | 288 | }
|
0 commit comments