Skip to content

Commit 62b846e

Browse files
committed
Remove use of macro_rules!
Signed-off-by: Jiahao XU <[email protected]>
1 parent 100fe5c commit 62b846e

File tree

3 files changed

+225
-133
lines changed

3 files changed

+225
-133
lines changed

library/std/src/sys/anonymous_pipe/mod.rs

+77-49
Original file line numberDiff line numberDiff line change
@@ -51,57 +51,85 @@ impl PipeWriter {
5151
}
5252
}
5353

54-
macro_rules! forward_io_read_traits {
55-
($name:ty) => {
56-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
57-
impl io::Read for $name {
58-
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
59-
self.0.read(buf)
60-
}
61-
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
62-
self.0.read_vectored(bufs)
63-
}
64-
#[inline]
65-
fn is_read_vectored(&self) -> bool {
66-
self.0.is_read_vectored()
67-
}
68-
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
69-
self.0.read_to_end(buf)
70-
}
71-
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
72-
self.0.read_buf(buf)
73-
}
74-
}
75-
};
54+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
55+
impl io::Read for &PipeReader {
56+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
57+
self.0.read(buf)
58+
}
59+
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
60+
self.0.read_vectored(bufs)
61+
}
62+
#[inline]
63+
fn is_read_vectored(&self) -> bool {
64+
self.0.is_read_vectored()
65+
}
66+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
67+
self.0.read_to_end(buf)
68+
}
69+
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
70+
self.0.read_buf(buf)
71+
}
7672
}
77-
forward_io_read_traits!(PipeReader);
78-
forward_io_read_traits!(&PipeReader);
79-
80-
macro_rules! forward_io_write_traits {
81-
($name:ty) => {
82-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
83-
impl io::Write for $name {
84-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
85-
self.0.write(buf)
86-
}
87-
#[inline]
88-
fn flush(&mut self) -> io::Result<()> {
89-
Ok(())
90-
}
91-
92-
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
93-
self.0.write_vectored(bufs)
94-
}
95-
96-
#[inline]
97-
fn is_write_vectored(&self) -> bool {
98-
self.0.is_write_vectored()
99-
}
100-
}
101-
};
73+
74+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
75+
impl io::Read for PipeReader {
76+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
77+
self.0.read(buf)
78+
}
79+
fn read_vectored(&mut self, bufs: &mut [io::IoSliceMut<'_>]) -> io::Result<usize> {
80+
self.0.read_vectored(bufs)
81+
}
82+
#[inline]
83+
fn is_read_vectored(&self) -> bool {
84+
self.0.is_read_vectored()
85+
}
86+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
87+
self.0.read_to_end(buf)
88+
}
89+
fn read_buf(&mut self, buf: io::BorrowedCursor<'_>) -> io::Result<()> {
90+
self.0.read_buf(buf)
91+
}
92+
}
93+
94+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
95+
impl io::Write for &PipeWriter {
96+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
97+
self.0.write(buf)
98+
}
99+
#[inline]
100+
fn flush(&mut self) -> io::Result<()> {
101+
Ok(())
102+
}
103+
104+
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
105+
self.0.write_vectored(bufs)
106+
}
107+
108+
#[inline]
109+
fn is_write_vectored(&self) -> bool {
110+
self.0.is_write_vectored()
111+
}
112+
}
113+
114+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
115+
impl io::Write for PipeWriter {
116+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
117+
self.0.write(buf)
118+
}
119+
#[inline]
120+
fn flush(&mut self) -> io::Result<()> {
121+
Ok(())
122+
}
123+
124+
fn write_vectored(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<usize> {
125+
self.0.write_vectored(bufs)
126+
}
127+
128+
#[inline]
129+
fn is_write_vectored(&self) -> bool {
130+
self.0.is_write_vectored()
131+
}
102132
}
103-
forward_io_write_traits!(PipeWriter);
104-
forward_io_write_traits!(&PipeWriter);
105133

106134
#[cfg(unix)]
107135
mod unix;

library/std/src/sys/anonymous_pipe/unix.rs

+73-42
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,79 @@ pub(super) fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
1818
anon_pipe().map(|(rx, tx)| (PipeReader(rx), PipeWriter(tx)))
1919
}
2020

21-
macro_rules! impl_traits {
22-
($name:ty) => {
23-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
24-
impl AsFd for $name {
25-
fn as_fd(&self) -> BorrowedFd<'_> {
26-
self.0.as_fd()
27-
}
28-
}
29-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
30-
impl AsRawFd for $name {
31-
fn as_raw_fd(&self) -> RawFd {
32-
self.0.as_raw_fd()
33-
}
34-
}
35-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
36-
impl From<$name> for OwnedFd {
37-
fn from(pipe: $name) -> Self {
38-
FileDesc::into_inner(AnonPipe::into_inner(pipe.0))
39-
}
40-
}
41-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
42-
impl FromRawFd for $name {
43-
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
44-
Self(AnonPipe::from_raw_fd(raw_fd))
45-
}
46-
}
47-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
48-
impl IntoRawFd for $name {
49-
fn into_raw_fd(self) -> RawFd {
50-
self.0.into_raw_fd()
51-
}
52-
}
53-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
54-
impl From<$name> for Stdio {
55-
fn from(pipe: $name) -> Self {
56-
Self::from(OwnedFd::from(pipe))
57-
}
58-
}
59-
};
60-
}
61-
impl_traits!(PipeReader);
62-
impl_traits!(PipeWriter);
21+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
22+
impl AsFd for PipeReader {
23+
fn as_fd(&self) -> BorrowedFd<'_> {
24+
self.0.as_fd()
25+
}
26+
}
27+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
28+
impl AsRawFd for PipeReader {
29+
fn as_raw_fd(&self) -> RawFd {
30+
self.0.as_raw_fd()
31+
}
32+
}
33+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
34+
impl From<PipeReader> for OwnedFd {
35+
fn from(pipe: PipeReader) -> Self {
36+
FileDesc::into_inner(AnonPipe::into_inner(pipe.0))
37+
}
38+
}
39+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
40+
impl FromRawFd for PipeReader {
41+
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
42+
Self(AnonPipe::from_raw_fd(raw_fd))
43+
}
44+
}
45+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
46+
impl IntoRawFd for PipeReader {
47+
fn into_raw_fd(self) -> RawFd {
48+
self.0.into_raw_fd()
49+
}
50+
}
51+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
52+
impl From<PipeReader> for Stdio {
53+
fn from(pipe: PipeReader) -> Self {
54+
Self::from(OwnedFd::from(pipe))
55+
}
56+
}
57+
58+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
59+
impl AsFd for PipeWriter {
60+
fn as_fd(&self) -> BorrowedFd<'_> {
61+
self.0.as_fd()
62+
}
63+
}
64+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
65+
impl AsRawFd for PipeWriter {
66+
fn as_raw_fd(&self) -> RawFd {
67+
self.0.as_raw_fd()
68+
}
69+
}
70+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
71+
impl From<PipeWriter> for OwnedFd {
72+
fn from(pipe: PipeWriter) -> Self {
73+
FileDesc::into_inner(AnonPipe::into_inner(pipe.0))
74+
}
75+
}
76+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
77+
impl FromRawFd for PipeWriter {
78+
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
79+
Self(AnonPipe::from_raw_fd(raw_fd))
80+
}
81+
}
82+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
83+
impl IntoRawFd for PipeWriter {
84+
fn into_raw_fd(self) -> RawFd {
85+
self.0.into_raw_fd()
86+
}
87+
}
88+
#[unstable(feature = "anonymous_pipe", issue = "127154")]
89+
impl From<PipeWriter> for Stdio {
90+
fn from(pipe: PipeWriter) -> Self {
91+
Self::from(OwnedFd::from(pipe))
92+
}
93+
}
6394

6495
fn convert_to_pipe(owned_fd: OwnedFd) -> io::Result<AnonPipe> {
6596
let file = File::from(owned_fd);

library/std/src/sys/anonymous_pipe/windows.rs

+75-42
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,83 @@ pub(super) fn pipe() -> io::Result<(PipeReader, PipeWriter)> {
1717
anon_pipe(true, false).map(|Pipes { ours, theirs }| (PipeReader(ours), PipeWriter(theirs)))
1818
}
1919

20-
macro_rules! impl_traits {
21-
($name:ty) => {
22-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
23-
impl AsHandle for $name {
24-
fn as_handle(&self) -> BorrowedHandle<'_> {
25-
self.0.handle().as_handle()
26-
}
27-
}
28-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
29-
impl AsRawHandle for $name {
30-
fn as_raw_handle(&self) -> RawHandle {
31-
self.0.handle().as_raw_handle()
32-
}
33-
}
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+
}
3445

35-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
36-
impl FromRawHandle for $name {
37-
unsafe fn from_raw_handle(raw_handle: RawHandle) -> Self {
38-
Self(AnonPipe::from_inner(Handle::from_raw_handle(raw_handle)))
39-
}
40-
}
41-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
42-
impl IntoRawHandle for $name {
43-
fn into_raw_handle(self) -> RawHandle {
44-
self.0.into_handle().into_raw_handle()
45-
}
46-
}
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+
}
4758

48-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
49-
impl From<$name> for OwnedHandle {
50-
fn from(pipe: $name) -> Self {
51-
Handle::into_inner(AnonPipe::into_inner(pipe.0))
52-
}
53-
}
54-
#[unstable(feature = "anonymous_pipe", issue = "127154")]
55-
impl From<$name> for Stdio {
56-
fn from(pipe: $name) -> Self {
57-
Self::from(OwnedHandle::from(pipe))
58-
}
59-
}
60-
};
61-
}
62-
impl_traits!(PipeReader);
63-
impl_traits!(PipeWriter);
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+
}
6497

6598
fn convert_to_pipe(owned_handle: OwnedHandle) -> io::Result<AnonPipe> {
6699
if unsafe { GetFileType(owned_handle.as_raw_handle()) } == FILE_TYPE_PIPE {

0 commit comments

Comments
 (0)