Skip to content

Commit f66306c

Browse files
committed
Implement AsHandleOrSocket and From<OwnedHandleOrSocket> for types.
Implement `AsHandleOrSocket` and `From<OwnedHandleOrSocket>` for types that implement `AsRawHandleOrSocket` and `IntoRawHandleOrSocket`.
1 parent c13c792 commit f66306c

File tree

16 files changed

+281
-16
lines changed

16 files changed

+281
-16
lines changed

cap-async-std/src/fs/dir.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ use {
2929
use {
3030
async_std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle},
3131
cap_primitives::fs::{symlink_dir, symlink_file},
32-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
32+
io_extras::os::windows::{
33+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
34+
OwnedHandleOrSocket, RawHandleOrSocket,
35+
},
3336
};
3437

3538
/// A reference to an open directory on a filesystem.
@@ -937,6 +940,14 @@ impl AsRawHandleOrSocket for Dir {
937940
}
938941
}
939942

943+
#[cfg(windows)]
944+
impl AsHandleOrSocket for Dir {
945+
#[inline]
946+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
947+
self.std_file.as_handle_or_socket()
948+
}
949+
}
950+
940951
#[cfg(not(windows))]
941952
impl IntoRawFd for Dir {
942953
#[inline]
@@ -977,6 +988,14 @@ impl IntoRawHandleOrSocket for Dir {
977988
}
978989
}
979990

991+
#[cfg(windows)]
992+
impl From<Dir> for OwnedHandleOrSocket {
993+
#[inline]
994+
fn from(dir: Dir) -> Self {
995+
dir.std_file.into()
996+
}
997+
}
998+
980999
/// Indicates how large a buffer to pre-allocate before reading the entire
9811000
/// file.
9821001
///

cap-async-std/src/fs/file.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use std::pin::Pin;
1919
#[cfg(windows)]
2020
use {
2121
async_std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle},
22-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
22+
io_extras::os::windows::{
23+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
24+
OwnedHandleOrSocket, RawHandleOrSocket,
25+
},
2326
};
2427

2528
/// A reference to an open file on a filesystem.
@@ -263,6 +266,14 @@ impl AsRawHandleOrSocket for File {
263266
}
264267
}
265268

269+
#[cfg(windows)]
270+
impl AsHandleOrSocket for File {
271+
#[inline]
272+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
273+
self.std.as_handle_or_socket()
274+
}
275+
}
276+
266277
#[cfg(not(windows))]
267278
impl IntoRawFd for File {
268279
#[inline]
@@ -303,6 +314,14 @@ impl IntoRawHandleOrSocket for File {
303314
}
304315
}
305316

317+
#[cfg(windows)]
318+
impl From<File> for OwnedHandleOrSocket {
319+
#[inline]
320+
fn from(file: File) -> Self {
321+
file.std.into()
322+
}
323+
}
324+
306325
impl Read for File {
307326
#[inline]
308327
fn poll_read(

cap-async-std/src/fs_utf8/dir.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use {
1616
#[cfg(windows)]
1717
use {
1818
async_std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle},
19-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
19+
io_extras::os::windows::{
20+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
21+
OwnedHandleOrSocket, RawHandleOrSocket,
22+
},
2023
};
2124

2225
/// A reference to an open directory on a filesystem.
@@ -704,6 +707,14 @@ impl AsHandle for Dir {
704707
}
705708
}
706709

710+
#[cfg(windows)]
711+
impl AsHandleOrSocket for Dir {
712+
#[inline]
713+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
714+
self.cap_std.as_handle_or_socket()
715+
}
716+
}
717+
707718
#[cfg(windows)]
708719
impl AsRawHandleOrSocket for Dir {
709720
#[inline]
@@ -752,6 +763,14 @@ impl IntoRawHandleOrSocket for Dir {
752763
}
753764
}
754765

766+
#[cfg(windows)]
767+
impl From<Dir> for OwnedHandleOrSocket {
768+
#[inline]
769+
fn from(dir: Dir) -> Self {
770+
dir.cap_std.into()
771+
}
772+
}
773+
755774
impl fmt::Debug for Dir {
756775
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
757776
self.cap_std.fmt(f)

cap-async-std/src/fs_utf8/file.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ use std::pin::Pin;
1818
#[cfg(windows)]
1919
use {
2020
async_std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle},
21-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
21+
io_extras::os::windows::{
22+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
23+
OwnedHandleOrSocket, RawHandleOrSocket,
24+
},
2225
};
2326

2427
/// A reference to an open file on a filesystem.
@@ -226,6 +229,14 @@ impl AsRawHandleOrSocket for File {
226229
}
227230
}
228231

232+
#[cfg(windows)]
233+
impl AsHandleOrSocket for File {
234+
#[inline]
235+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
236+
self.cap_std.as_handle_or_socket()
237+
}
238+
}
239+
229240
#[cfg(not(windows))]
230241
impl IntoRawFd for File {
231242
#[inline]
@@ -266,6 +277,14 @@ impl IntoRawHandleOrSocket for File {
266277
}
267278
}
268279

280+
#[cfg(windows)]
281+
impl From<File> for OwnedHandleOrSocket {
282+
#[inline]
283+
fn from(file: File) -> Self {
284+
file.cap_std.into()
285+
}
286+
}
287+
269288
impl Read for File {
270289
#[inline]
271290
fn poll_read(

cap-async-std/src/fs_utf8/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ fn from_utf8<'a>(path: &'a Utf8Path) -> std::io::Result<async_std::path::PathBuf
5656
Ok(path.into())
5757
}
5858

59-
6059
fn to_utf8<P: AsRef<async_std::path::Path>>(path: P) -> std::io::Result<Utf8PathBuf> {
6160
#[cfg(not(feature = "arf_strings"))]
6261
#[cfg(not(windows))]

cap-async-std/src/net/tcp_listener.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use std::fmt;
1010
#[cfg(windows)]
1111
use {
1212
async_std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket},
13-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
13+
io_extras::os::windows::{
14+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
15+
OwnedHandleOrSocket, RawHandleOrSocket,
16+
},
1417
};
1518

1619
/// A TCP socket server, listening for connections.
@@ -153,6 +156,14 @@ impl AsRawHandleOrSocket for TcpListener {
153156
}
154157
}
155158

159+
#[cfg(windows)]
160+
impl AsHandleOrSocket for TcpListener {
161+
#[inline]
162+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
163+
self.std.as_handle_or_socket()
164+
}
165+
}
166+
156167
#[cfg(not(windows))]
157168
impl IntoRawFd for TcpListener {
158169
#[inline]
@@ -193,6 +204,14 @@ impl IntoRawHandleOrSocket for TcpListener {
193204
}
194205
}
195206

207+
#[cfg(windows)]
208+
impl From<TcpListener> for OwnedHandleOrSocket {
209+
#[inline]
210+
fn from(listener: TcpListener) -> Self {
211+
listener.std.into()
212+
}
213+
}
214+
196215
impl fmt::Debug for TcpListener {
197216
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
198217
self.std.fmt(f)

cap-async-std/src/net/tcp_stream.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use std::pin::Pin;
1313
#[cfg(windows)]
1414
use {
1515
async_std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket},
16-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
16+
io_extras::os::windows::{
17+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
18+
OwnedHandleOrSocket, RawHandleOrSocket,
19+
},
1720
};
1821

1922
/// A TCP stream between a local and a remote socket.
@@ -197,6 +200,14 @@ impl AsRawHandleOrSocket for TcpStream {
197200
}
198201
}
199202

203+
#[cfg(windows)]
204+
impl AsHandleOrSocket for TcpStream {
205+
#[inline]
206+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
207+
self.std.as_handle_or_socket()
208+
}
209+
}
210+
200211
#[cfg(not(windows))]
201212
impl IntoRawFd for TcpStream {
202213
#[inline]
@@ -237,6 +248,14 @@ impl IntoRawHandleOrSocket for TcpStream {
237248
}
238249
}
239250

251+
#[cfg(windows)]
252+
impl From<TcpStream> for OwnedHandleOrSocket {
253+
#[inline]
254+
fn from(stream: TcpStream) -> Self {
255+
stream.std.into()
256+
}
257+
}
258+
240259
impl Read for TcpStream {
241260
#[inline]
242261
fn poll_read(

cap-async-std/src/net/udp_socket.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use std::fmt;
1010
#[cfg(windows)]
1111
use {
1212
async_std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket},
13-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
13+
io_extras::os::windows::{
14+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
15+
OwnedHandleOrSocket, RawHandleOrSocket,
16+
},
1417
};
1518

1619
/// A UDP socket.
@@ -298,6 +301,14 @@ impl AsRawHandleOrSocket for UdpSocket {
298301
}
299302
}
300303

304+
#[cfg(windows)]
305+
impl AsHandleOrSocket for UdpSocket {
306+
#[inline]
307+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
308+
self.std.as_handle_or_socket()
309+
}
310+
}
311+
301312
#[cfg(not(windows))]
302313
impl IntoRawFd for UdpSocket {
303314
#[inline]
@@ -338,6 +349,14 @@ impl IntoRawHandleOrSocket for UdpSocket {
338349
}
339350
}
340351

352+
#[cfg(windows)]
353+
impl From<UdpSocket> for OwnedHandleOrSocket {
354+
#[inline]
355+
fn from(socket: UdpSocket) -> Self {
356+
socket.std.into()
357+
}
358+
}
359+
341360
impl fmt::Debug for UdpSocket {
342361
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
343362
self.std.fmt(f)

cap-primitives/src/time/system_clock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl SystemClock {
1717
///
1818
/// This corresponds to [`std::time::SystemTime::UNIX_EPOCH`].
1919
pub const UNIX_EPOCH: SystemTime = SystemTime {
20-
std: time::SystemTime::UNIX_EPOCH
20+
std: time::SystemTime::UNIX_EPOCH,
2121
};
2222

2323
/// Constructs a new instance of `Self`.

cap-std/src/fs/dir.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ use {
2727
#[cfg(windows)]
2828
use {
2929
cap_primitives::fs::{symlink_dir, symlink_file},
30-
io_extras::os::windows::{AsRawHandleOrSocket, IntoRawHandleOrSocket, RawHandleOrSocket},
30+
io_extras::os::windows::{
31+
AsHandleOrSocket, AsRawHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket,
32+
OwnedHandleOrSocket, RawHandleOrSocket,
33+
},
3134
std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle},
3235
};
3336

@@ -759,6 +762,14 @@ impl AsRawHandleOrSocket for Dir {
759762
}
760763
}
761764

765+
#[cfg(windows)]
766+
impl AsHandleOrSocket for Dir {
767+
#[inline]
768+
fn as_handle_or_socket(&self) -> BorrowedHandleOrSocket<'_> {
769+
self.std_file.as_handle_or_socket()
770+
}
771+
}
772+
762773
#[cfg(not(windows))]
763774
impl IntoRawFd for Dir {
764775
#[inline]
@@ -799,6 +810,14 @@ impl IntoRawHandleOrSocket for Dir {
799810
}
800811
}
801812

813+
#[cfg(windows)]
814+
impl From<Dir> for OwnedHandleOrSocket {
815+
#[inline]
816+
fn from(dir: Dir) -> Self {
817+
dir.std_file.into()
818+
}
819+
}
820+
802821
/// Indicates how large a buffer to pre-allocate before reading the entire
803822
/// file.
804823
///

0 commit comments

Comments
 (0)