Skip to content

Commit 14af59c

Browse files
committed
Port to the new Windows io_safety traits.
1 parent e3fffe6 commit 14af59c

File tree

13 files changed

+91
-91
lines changed

13 files changed

+91
-91
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use cap_primitives::AmbientAuthority;
1717
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
1818
use io_lifetimes::{AsFilelike, FromFilelike};
1919
#[cfg(windows)]
20-
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
20+
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
2121
use std::fmt;
2222
#[cfg(unix)]
2323
use {
@@ -887,10 +887,10 @@ impl FromRawHandle for Dir {
887887
}
888888

889889
#[cfg(windows)]
890-
impl FromHandle for Dir {
890+
impl From<OwnedHandle> for Dir {
891891
#[inline]
892-
fn from_handle(handle: OwnedHandle) -> Self {
893-
Self::from_std_file(fs::File::from_handle(handle))
892+
fn from(handle: OwnedHandle) -> Self {
893+
Self::from_std_file(fs::File::from(handle))
894894
}
895895
}
896896

@@ -959,10 +959,10 @@ impl IntoRawHandle for Dir {
959959
}
960960

961961
#[cfg(windows)]
962-
impl IntoHandle for Dir {
962+
impl From<Dir> for OwnedHandle {
963963
#[inline]
964-
fn into_handle(self) -> OwnedHandle {
965-
self.std_file.into_handle()
964+
fn from(dir: Dir) -> OwnedHandle {
965+
dir.std_file.into()
966966
}
967967
}
968968

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use io_lifetimes::AsFilelike;
1212
#[cfg(not(windows))]
1313
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
1414
#[cfg(windows)]
15-
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
15+
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
1616
use std::fmt;
1717
use std::path::Path;
1818
use std::pin::Pin;
@@ -213,10 +213,10 @@ impl FromRawHandle for File {
213213
}
214214

215215
#[cfg(windows)]
216-
impl FromHandle for File {
216+
impl From<OwnedHandle> for File {
217217
#[inline]
218-
fn from_handle(handle: OwnedHandle) -> Self {
219-
Self::from_std(fs::File::from_handle(handle))
218+
fn from(handle: OwnedHandle) -> Self {
219+
Self::from_std(fs::File::from(handle))
220220
}
221221
}
222222

@@ -285,10 +285,10 @@ impl IntoRawHandle for File {
285285
}
286286

287287
#[cfg(windows)]
288-
impl IntoHandle for File {
288+
impl From<File> for OwnedHandle {
289289
#[inline]
290-
fn into_handle(self) -> OwnedHandle {
291-
self.std.into_handle()
290+
fn from(file: File) -> OwnedHandle {
291+
file.std.into()
292292
}
293293
}
294294

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cap_primitives::AmbientAuthority;
66
#[cfg(not(windows))]
77
use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
88
#[cfg(windows)]
9-
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
9+
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
1010
use std::fmt;
1111
#[cfg(unix)]
1212
use {
@@ -662,10 +662,10 @@ impl FromRawHandle for Dir {
662662
}
663663

664664
#[cfg(windows)]
665-
impl FromHandle for Dir {
665+
impl From<OwnedHandle> for Dir {
666666
#[inline]
667-
fn from_handle(handle: OwnedHandle) -> Self {
668-
Self::from_std_file(fs::File::from_handle(handle))
667+
fn from(handle: OwnedHandle) -> Self {
668+
Self::from_std_file(fs::File::from(handle))
669669
}
670670
}
671671

@@ -734,10 +734,10 @@ impl IntoRawHandle for Dir {
734734
}
735735

736736
#[cfg(windows)]
737-
impl IntoHandle for Dir {
737+
impl From<Dir> for OwnedHandle {
738738
#[inline]
739-
fn into_handle(self) -> OwnedHandle {
740-
self.cap_std.into_handle()
739+
fn from(dir: Dir) -> OwnedHandle {
740+
dir.cap_std.into()
741741
}
742742
}
743743

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use cap_primitives::AmbientAuthority;
1212
#[cfg(not(windows))]
1313
use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
1414
#[cfg(windows)]
15-
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
15+
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
1616
use std::fmt;
1717
use std::pin::Pin;
1818
#[cfg(windows)]
@@ -176,10 +176,10 @@ impl FromRawHandle for File {
176176
}
177177

178178
#[cfg(windows)]
179-
impl FromHandle for File {
179+
impl From<OwnedHandle> for File {
180180
#[inline]
181-
fn from_handle(handle: OwnedHandle) -> Self {
182-
Self::from_std(fs::File::from_handle(handle))
181+
fn from(handle: OwnedHandle) -> Self {
182+
Self::from_std(fs::File::from(handle))
183183
}
184184
}
185185

@@ -248,10 +248,10 @@ impl IntoRawHandle for File {
248248
}
249249

250250
#[cfg(windows)]
251-
impl IntoHandle for File {
251+
impl From<File> for OwnedHandle {
252252
#[inline]
253-
fn into_handle(self) -> OwnedHandle {
254-
self.cap_std.into_handle()
253+
fn from(file: File) -> OwnedHandle {
254+
file.cap_std.into()
255255
}
256256
}
257257

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use async_std::{io, net};
55
#[cfg(not(windows))]
66
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
77
#[cfg(windows)]
8-
use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket};
8+
use io_lifetimes::{AsSocket, BorrowedSocket, OwnedSocket};
99
use std::fmt;
1010
#[cfg(windows)]
1111
use {
@@ -103,10 +103,10 @@ impl FromRawSocket for TcpListener {
103103
}
104104

105105
#[cfg(windows)]
106-
impl FromSocket for TcpListener {
106+
impl From<OwnedSocket> for TcpListener {
107107
#[inline]
108-
fn from_socket(socket: OwnedSocket) -> Self {
109-
Self::from_std(net::TcpListener::from_socket(socket))
108+
fn from(socket: OwnedSocket) -> Self {
109+
Self::from_std(net::TcpListener::from(socket))
110110
}
111111
}
112112

@@ -175,10 +175,10 @@ impl IntoRawSocket for TcpListener {
175175
}
176176

177177
#[cfg(windows)]
178-
impl IntoSocket for TcpListener {
178+
impl From<TcpListener> for OwnedSocket {
179179
#[inline]
180-
fn into_socket(self) -> OwnedSocket {
181-
self.std.into_socket()
180+
fn from(listener: TcpListener) -> OwnedSocket {
181+
listener.std.into()
182182
}
183183
}
184184

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use async_std::task::{Context, Poll};
77
#[cfg(not(windows))]
88
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
99
#[cfg(windows)]
10-
use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket};
10+
use io_lifetimes::{AsSocket, BorrowedSocket, OwnedSocket};
1111
use std::fmt;
1212
use std::pin::Pin;
1313
#[cfg(windows)]
@@ -147,10 +147,10 @@ impl FromRawSocket for TcpStream {
147147
}
148148

149149
#[cfg(windows)]
150-
impl FromSocket for TcpStream {
150+
impl From<OwnedSocket> for TcpStream {
151151
#[inline]
152-
fn from_socket(socket: OwnedSocket) -> Self {
153-
Self::from_std(net::TcpStream::from_socket(socket))
152+
fn from(socket: OwnedSocket) -> Self {
153+
Self::from_std(net::TcpStream::from(socket))
154154
}
155155
}
156156

@@ -219,10 +219,10 @@ impl IntoRawSocket for TcpStream {
219219
}
220220

221221
#[cfg(windows)]
222-
impl IntoSocket for TcpStream {
222+
impl From<TcpStream> for OwnedSocket {
223223
#[inline]
224-
fn into_socket(self) -> OwnedSocket {
225-
self.std.into_socket()
224+
fn from(stream: TcpStream) -> OwnedSocket {
225+
stream.std.into()
226226
}
227227
}
228228

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use async_std::{io, net};
55
#[cfg(not(windows))]
66
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
77
#[cfg(windows)]
8-
use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket};
8+
use io_lifetimes::{AsSocket, BorrowedSocket, OwnedSocket};
99
use std::fmt;
1010
#[cfg(windows)]
1111
use {
@@ -248,10 +248,10 @@ impl FromRawSocket for UdpSocket {
248248
}
249249

250250
#[cfg(windows)]
251-
impl FromSocket for UdpSocket {
251+
impl From<OwnedSocket> for UdpSocket {
252252
#[inline]
253-
fn from_socket(socket: OwnedSocket) -> Self {
254-
Self::from_std(net::UdpSocket::from_socket(socket))
253+
fn from(socket: OwnedSocket) -> Self {
254+
Self::from_std(net::UdpSocket::from(socket))
255255
}
256256
}
257257

@@ -320,10 +320,10 @@ impl IntoRawSocket for UdpSocket {
320320
}
321321

322322
#[cfg(windows)]
323-
impl IntoSocket for UdpSocket {
323+
impl From<UdpSocket> for OwnedSocket {
324324
#[inline]
325-
fn into_socket(self) -> OwnedSocket {
326-
self.std.into_socket()
325+
fn from(socket: UdpSocket) -> OwnedSocket {
326+
self.std.into()
327327
}
328328
}
329329

cap-std/src/fs/dir.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use io_lifetimes::AsFilelike;
1313
#[cfg(not(windows))]
1414
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
1515
#[cfg(windows)]
16-
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
16+
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
1717
#[cfg(target_os = "wasi")]
1818
use rustix::fs::OpenOptionsExt;
1919
use std::io::{self, Read, Write};
@@ -709,10 +709,10 @@ impl FromRawHandle for Dir {
709709
}
710710

711711
#[cfg(windows)]
712-
impl FromHandle for Dir {
712+
impl From<OwnedHandle> for Dir {
713713
#[inline]
714-
fn from_handle(handle: OwnedHandle) -> Self {
715-
Self::from_std_file(fs::File::from_handle(handle))
714+
fn from(handle: OwnedHandle) -> Self {
715+
Self::from_std_file(fs::File::from(handle))
716716
}
717717
}
718718

@@ -781,10 +781,10 @@ impl IntoRawHandle for Dir {
781781
}
782782

783783
#[cfg(windows)]
784-
impl IntoHandle for Dir {
784+
impl From<Dir> for OwnedHandle {
785785
#[inline]
786-
fn into_handle(self) -> OwnedHandle {
787-
self.std_file.into_handle()
786+
fn from(dir: Dir) -> OwnedHandle {
787+
dir.std_file.into()
788788
}
789789
}
790790

cap-std/src/fs_utf8/dir.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
99
#[cfg(not(windows))]
1010
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
1111
#[cfg(windows)]
12-
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
12+
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
1313
use std::{fmt, fs, io};
1414
#[cfg(windows)]
1515
use {
@@ -646,12 +646,12 @@ impl FromRawHandle for Dir {
646646
}
647647

648648
#[cfg(windows)]
649-
impl FromHandle for Dir {
649+
impl From<OwnedHandle> for Dir {
650650
/// To prevent race conditions on Windows, the handle must be opened
651651
/// without `FILE_SHARE_DELETE`.
652652
#[inline]
653-
fn from_handle(handle: OwnedHandle) -> Self {
654-
Self::from_std_file(fs::File::from_handle(handle))
653+
fn from(handle: OwnedHandle) -> Self {
654+
Self::from_std_file(fs::File::from(handle))
655655
}
656656
}
657657

@@ -720,10 +720,10 @@ impl IntoRawHandle for Dir {
720720
}
721721

722722
#[cfg(windows)]
723-
impl IntoHandle for Dir {
723+
impl From<Dir> for OwnedHandle {
724724
#[inline]
725-
fn into_handle(self) -> OwnedHandle {
726-
self.cap_std.into_handle()
725+
fn from(dir: Dir) -> OwnedHandle {
726+
dir.cap_std.into()
727727
}
728728
}
729729

cap-std/src/fs_utf8/file.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
77
#[cfg(not(windows))]
88
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
99
#[cfg(windows)]
10-
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
10+
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
1111
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
1212
#[cfg(target_os = "wasi")]
1313
use std::path::Path;
@@ -182,10 +182,10 @@ impl FromRawHandle for File {
182182
}
183183

184184
#[cfg(windows)]
185-
impl FromHandle for File {
185+
impl From<OwnedHandle> for File {
186186
#[inline]
187-
fn from_handle(handle: OwnedHandle) -> Self {
188-
Self::from_std(fs::File::from_handle(handle))
187+
fn from(handle: OwnedHandle) -> Self {
188+
Self::from_std(fs::File::from(handle))
189189
}
190190
}
191191

@@ -254,10 +254,10 @@ impl IntoRawHandle for File {
254254
}
255255

256256
#[cfg(windows)]
257-
impl IntoHandle for File {
257+
impl From<File> for OwnedHandle {
258258
#[inline]
259-
fn into_handle(self) -> OwnedHandle {
260-
self.cap_std.into_handle()
259+
fn from(file: File) -> OwnedHandle {
260+
file.cap_std.into()
261261
}
262262
}
263263

0 commit comments

Comments
 (0)