@@ -12,7 +12,7 @@ use std::io::{Cursor, ErrorKind};
12
12
use std:: io:: Stdout ;
13
13
14
14
#[ cfg( feature = "rawfd" ) ]
15
- use std:: os:: fd:: AsRawFd ;
15
+ use std:: os:: fd:: { AsRawFd , RawFd } ;
16
16
17
17
macro_rules! retry_eintr {
18
18
( $io_call: expr) => {
@@ -127,7 +127,7 @@ pub trait WriteVolatile {
127
127
// We explicitly implement our traits for [`std::fs::File`] and [`std::os::unix::net::UnixStream`]
128
128
// instead of providing blanket implementation for [`AsRawFd`] due to trait coherence limitations: A
129
129
// blanket implementation would prevent us from providing implementations for `&mut [u8]` below, as
130
- // "an upstream crate could implement AsRawFd for &mut [u8]` .
130
+ // "an upstream crate could implement AsRawFd for &mut [u8]" .
131
131
132
132
macro_rules! impl_read_write_volatile_for_raw_fd {
133
133
( $raw_fd_ty: ty) => {
@@ -137,7 +137,27 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
137
137
& mut self ,
138
138
buf: & mut VolatileSlice <B >,
139
139
) -> Result <usize , VolatileMemoryError > {
140
- read_volatile_raw_fd( self , buf)
140
+ read_volatile_raw_fd( self . as_raw_fd( ) , buf)
141
+ }
142
+ }
143
+
144
+ #[ cfg( feature = "rawfd" ) ]
145
+ impl ReadVolatile for & $raw_fd_ty {
146
+ fn read_volatile<B : BitmapSlice >(
147
+ & mut self ,
148
+ buf: & mut VolatileSlice <B >,
149
+ ) -> Result <usize , VolatileMemoryError > {
150
+ read_volatile_raw_fd( self . as_raw_fd( ) , buf)
151
+ }
152
+ }
153
+
154
+ #[ cfg( feature = "rawfd" ) ]
155
+ impl ReadVolatile for & mut $raw_fd_ty {
156
+ fn read_volatile<B : BitmapSlice >(
157
+ & mut self ,
158
+ buf: & mut VolatileSlice <B >,
159
+ ) -> Result <usize , VolatileMemoryError > {
160
+ read_volatile_raw_fd( self . as_raw_fd( ) , buf)
141
161
}
142
162
}
143
163
@@ -147,7 +167,27 @@ macro_rules! impl_read_write_volatile_for_raw_fd {
147
167
& mut self ,
148
168
buf: & VolatileSlice <B >,
149
169
) -> Result <usize , VolatileMemoryError > {
150
- write_volatile_raw_fd( self , buf)
170
+ write_volatile_raw_fd( self . as_raw_fd( ) , buf)
171
+ }
172
+ }
173
+
174
+ #[ cfg( feature = "rawfd" ) ]
175
+ impl WriteVolatile for & $raw_fd_ty {
176
+ fn write_volatile<B : BitmapSlice >(
177
+ & mut self ,
178
+ buf: & VolatileSlice <B >,
179
+ ) -> Result <usize , VolatileMemoryError > {
180
+ write_volatile_raw_fd( self . as_raw_fd( ) , buf)
181
+ }
182
+ }
183
+
184
+ #[ cfg( feature = "rawfd" ) ]
185
+ impl WriteVolatile for & mut $raw_fd_ty {
186
+ fn write_volatile<B : BitmapSlice >(
187
+ & mut self ,
188
+ buf: & VolatileSlice <B >,
189
+ ) -> Result <usize , VolatileMemoryError > {
190
+ write_volatile_raw_fd( self . as_raw_fd( ) , buf)
151
191
}
152
192
}
153
193
} ;
@@ -159,7 +199,17 @@ impl WriteVolatile for Stdout {
159
199
& mut self ,
160
200
buf : & VolatileSlice < B > ,
161
201
) -> Result < usize , VolatileMemoryError > {
162
- write_volatile_raw_fd ( self , buf)
202
+ write_volatile_raw_fd ( self . as_raw_fd ( ) , buf)
203
+ }
204
+ }
205
+
206
+ #[ cfg( feature = "rawfd" ) ]
207
+ impl WriteVolatile for & Stdout {
208
+ fn write_volatile < B : BitmapSlice > (
209
+ & mut self ,
210
+ buf : & VolatileSlice < B > ,
211
+ ) -> Result < usize , VolatileMemoryError > {
212
+ write_volatile_raw_fd ( self . as_raw_fd ( ) , buf)
163
213
}
164
214
}
165
215
@@ -174,8 +224,8 @@ impl_read_write_volatile_for_raw_fd!(std::os::fd::BorrowedFd<'_>);
174
224
///
175
225
/// Returns the numbers of bytes read.
176
226
#[ cfg( feature = "rawfd" ) ]
177
- fn read_volatile_raw_fd < Fd : AsRawFd > (
178
- raw_fd : & mut Fd ,
227
+ fn read_volatile_raw_fd (
228
+ raw_fd : RawFd ,
179
229
buf : & mut VolatileSlice < impl BitmapSlice > ,
180
230
) -> Result < usize , VolatileMemoryError > {
181
231
let fd = raw_fd. as_raw_fd ( ) ;
@@ -205,8 +255,8 @@ fn read_volatile_raw_fd<Fd: AsRawFd>(
205
255
///
206
256
/// Returns the numbers of bytes written.
207
257
#[ cfg( feature = "rawfd" ) ]
208
- fn write_volatile_raw_fd < Fd : AsRawFd > (
209
- raw_fd : & mut Fd ,
258
+ fn write_volatile_raw_fd (
259
+ raw_fd : RawFd ,
210
260
buf : & VolatileSlice < impl BitmapSlice > ,
211
261
) -> Result < usize , VolatileMemoryError > {
212
262
let fd = raw_fd. as_raw_fd ( ) ;
0 commit comments