|
| 1 | +use super::*; |
| 2 | + |
| 3 | +use crate::{ |
| 4 | + os::windows::io::{ |
| 5 | + AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle, |
| 6 | + }, |
| 7 | + process::Stdio, |
| 8 | + sys::{ |
| 9 | + handle::Handle, |
| 10 | + pipe::{anon_pipe, AnonPipe, Pipes}, |
| 11 | + }, |
| 12 | + sys_common::{FromInner, IntoInner}, |
| 13 | +}; |
| 14 | + |
| 15 | +#[inline] |
| 16 | +pub(super) fn pipe() -> io::Result<(PipeReader, PipeWriter)> { |
| 17 | + anon_pipe(true, false).map(|Pipes { ours, theirs }| (PipeReader(ours), PipeWriter(theirs))) |
| 18 | +} |
| 19 | + |
| 20 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 21 | +impl AsHandle for PipeReader { |
| 22 | + fn as_handle(&self) -> BorrowedHandle<'_> { |
| 23 | + self.0.handle().as_handle() |
| 24 | + } |
| 25 | +} |
| 26 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 27 | +impl AsRawHandle for PipeReader { |
| 28 | + fn as_raw_handle(&self) -> RawHandle { |
| 29 | + self.0.handle().as_raw_handle() |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 34 | +impl FromRawHandle for PipeReader { |
| 35 | + unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self { |
| 36 | + Self(AnonPipe::from_inner(Handle::from_raw_handle(raw_handle))) |
| 37 | + } |
| 38 | +} |
| 39 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 40 | +impl IntoRawHandle for PipeReader { |
| 41 | + fn into_raw_handle(self) -> RawHandle { |
| 42 | + self.0.into_handle().into_raw_handle() |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 47 | +impl From<PipeReader> for OwnedHandle { |
| 48 | + fn from(pipe: PipeReader) -> Self { |
| 49 | + Handle::into_inner(AnonPipe::into_inner(pipe.0)) |
| 50 | + } |
| 51 | +} |
| 52 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 53 | +impl From<PipeReader> for Stdio { |
| 54 | + fn from(pipe: PipeReader) -> Self { |
| 55 | + Self::from(OwnedHandle::from(pipe)) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 60 | +impl AsHandle for PipeWriter { |
| 61 | + fn as_handle(&self) -> BorrowedHandle<'_> { |
| 62 | + self.0.handle().as_handle() |
| 63 | + } |
| 64 | +} |
| 65 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 66 | +impl AsRawHandle for PipeWriter { |
| 67 | + fn as_raw_handle(&self) -> RawHandle { |
| 68 | + self.0.handle().as_raw_handle() |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 73 | +impl FromRawHandle for PipeWriter { |
| 74 | + unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self { |
| 75 | + Self(AnonPipe::from_inner(Handle::from_raw_handle(raw_handle))) |
| 76 | + } |
| 77 | +} |
| 78 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 79 | +impl IntoRawHandle for PipeWriter { |
| 80 | + fn into_raw_handle(self) -> RawHandle { |
| 81 | + self.0.into_handle().into_raw_handle() |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 86 | +impl From<PipeWriter> for OwnedHandle { |
| 87 | + fn from(pipe: PipeWriter) -> Self { |
| 88 | + Handle::into_inner(AnonPipe::into_inner(pipe.0)) |
| 89 | + } |
| 90 | +} |
| 91 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 92 | +impl From<PipeWriter> for Stdio { |
| 93 | + fn from(pipe: PipeWriter) -> Self { |
| 94 | + Self::from(OwnedHandle::from(pipe)) |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +fn convert_to_pipe(owned_handle: OwnedHandle) -> AnonPipe { |
| 99 | + AnonPipe::from_inner(Handle::from_inner(owned_handle)) |
| 100 | +} |
| 101 | + |
| 102 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 103 | +impl From<OwnedHandle> for PipeReader { |
| 104 | + fn from(owned_handle: OwnedHandle) -> Self { |
| 105 | + Self(convert_to_pipe(owned_handle)) |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +#[unstable(feature = "anonymous_pipe", issue = "127154")] |
| 110 | +impl From<OwnedHandle> for PipeWriter { |
| 111 | + fn from(owned_handle: OwnedHandle) -> Self { |
| 112 | + Self(convert_to_pipe(owned_handle)) |
| 113 | + } |
| 114 | +} |
0 commit comments