Skip to content

Commit

Permalink
Port to the new Windows io_safety traits.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Aug 23, 2022
1 parent e3fffe6 commit 14af59c
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 91 deletions.
14 changes: 7 additions & 7 deletions cap-async-std/src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use cap_primitives::AmbientAuthority;
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
use io_lifetimes::{AsFilelike, FromFilelike};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
use std::fmt;
#[cfg(unix)]
use {
Expand Down Expand Up @@ -887,10 +887,10 @@ impl FromRawHandle for Dir {
}

#[cfg(windows)]
impl FromHandle for Dir {
impl From<OwnedHandle> for Dir {
#[inline]
fn from_handle(handle: OwnedHandle) -> Self {
Self::from_std_file(fs::File::from_handle(handle))
fn from(handle: OwnedHandle) -> Self {
Self::from_std_file(fs::File::from(handle))
}
}

Expand Down Expand Up @@ -959,10 +959,10 @@ impl IntoRawHandle for Dir {
}

#[cfg(windows)]
impl IntoHandle for Dir {
impl From<Dir> for OwnedHandle {
#[inline]
fn into_handle(self) -> OwnedHandle {
self.std_file.into_handle()
fn from(dir: Dir) -> OwnedHandle {
dir.std_file.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-async-std/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use io_lifetimes::AsFilelike;
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
use std::fmt;
use std::path::Path;
use std::pin::Pin;
Expand Down Expand Up @@ -213,10 +213,10 @@ impl FromRawHandle for File {
}

#[cfg(windows)]
impl FromHandle for File {
impl From<OwnedHandle> for File {
#[inline]
fn from_handle(handle: OwnedHandle) -> Self {
Self::from_std(fs::File::from_handle(handle))
fn from(handle: OwnedHandle) -> Self {
Self::from_std(fs::File::from(handle))
}
}

Expand Down Expand Up @@ -285,10 +285,10 @@ impl IntoRawHandle for File {
}

#[cfg(windows)]
impl IntoHandle for File {
impl From<File> for OwnedHandle {
#[inline]
fn into_handle(self) -> OwnedHandle {
self.std.into_handle()
fn from(file: File) -> OwnedHandle {
file.std.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-async-std/src/fs_utf8/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cap_primitives::AmbientAuthority;
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
use std::fmt;
#[cfg(unix)]
use {
Expand Down Expand Up @@ -662,10 +662,10 @@ impl FromRawHandle for Dir {
}

#[cfg(windows)]
impl FromHandle for Dir {
impl From<OwnedHandle> for Dir {
#[inline]
fn from_handle(handle: OwnedHandle) -> Self {
Self::from_std_file(fs::File::from_handle(handle))
fn from(handle: OwnedHandle) -> Self {
Self::from_std_file(fs::File::from(handle))
}
}

Expand Down Expand Up @@ -734,10 +734,10 @@ impl IntoRawHandle for Dir {
}

#[cfg(windows)]
impl IntoHandle for Dir {
impl From<Dir> for OwnedHandle {
#[inline]
fn into_handle(self) -> OwnedHandle {
self.cap_std.into_handle()
fn from(dir: Dir) -> OwnedHandle {
dir.cap_std.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-async-std/src/fs_utf8/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cap_primitives::AmbientAuthority;
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
use std::fmt;
use std::pin::Pin;
#[cfg(windows)]
Expand Down Expand Up @@ -176,10 +176,10 @@ impl FromRawHandle for File {
}

#[cfg(windows)]
impl FromHandle for File {
impl From<OwnedHandle> for File {
#[inline]
fn from_handle(handle: OwnedHandle) -> Self {
Self::from_std(fs::File::from_handle(handle))
fn from(handle: OwnedHandle) -> Self {
Self::from_std(fs::File::from(handle))
}
}

Expand Down Expand Up @@ -248,10 +248,10 @@ impl IntoRawHandle for File {
}

#[cfg(windows)]
impl IntoHandle for File {
impl From<File> for OwnedHandle {
#[inline]
fn into_handle(self) -> OwnedHandle {
self.cap_std.into_handle()
fn from(file: File) -> OwnedHandle {
file.cap_std.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-async-std/src/net/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_std::{io, net};
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket};
use io_lifetimes::{AsSocket, BorrowedSocket, OwnedSocket};
use std::fmt;
#[cfg(windows)]
use {
Expand Down Expand Up @@ -103,10 +103,10 @@ impl FromRawSocket for TcpListener {
}

#[cfg(windows)]
impl FromSocket for TcpListener {
impl From<OwnedSocket> for TcpListener {
#[inline]
fn from_socket(socket: OwnedSocket) -> Self {
Self::from_std(net::TcpListener::from_socket(socket))
fn from(socket: OwnedSocket) -> Self {
Self::from_std(net::TcpListener::from(socket))
}
}

Expand Down Expand Up @@ -175,10 +175,10 @@ impl IntoRawSocket for TcpListener {
}

#[cfg(windows)]
impl IntoSocket for TcpListener {
impl From<TcpListener> for OwnedSocket {
#[inline]
fn into_socket(self) -> OwnedSocket {
self.std.into_socket()
fn from(listener: TcpListener) -> OwnedSocket {
listener.std.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-async-std/src/net/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use async_std::task::{Context, Poll};
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket};
use io_lifetimes::{AsSocket, BorrowedSocket, OwnedSocket};
use std::fmt;
use std::pin::Pin;
#[cfg(windows)]
Expand Down Expand Up @@ -147,10 +147,10 @@ impl FromRawSocket for TcpStream {
}

#[cfg(windows)]
impl FromSocket for TcpStream {
impl From<OwnedSocket> for TcpStream {
#[inline]
fn from_socket(socket: OwnedSocket) -> Self {
Self::from_std(net::TcpStream::from_socket(socket))
fn from(socket: OwnedSocket) -> Self {
Self::from_std(net::TcpStream::from(socket))
}
}

Expand Down Expand Up @@ -219,10 +219,10 @@ impl IntoRawSocket for TcpStream {
}

#[cfg(windows)]
impl IntoSocket for TcpStream {
impl From<TcpStream> for OwnedSocket {
#[inline]
fn into_socket(self) -> OwnedSocket {
self.std.into_socket()
fn from(stream: TcpStream) -> OwnedSocket {
stream.std.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-async-std/src/net/udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_std::{io, net};
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket};
use io_lifetimes::{AsSocket, BorrowedSocket, OwnedSocket};
use std::fmt;
#[cfg(windows)]
use {
Expand Down Expand Up @@ -248,10 +248,10 @@ impl FromRawSocket for UdpSocket {
}

#[cfg(windows)]
impl FromSocket for UdpSocket {
impl From<OwnedSocket> for UdpSocket {
#[inline]
fn from_socket(socket: OwnedSocket) -> Self {
Self::from_std(net::UdpSocket::from_socket(socket))
fn from(socket: OwnedSocket) -> Self {
Self::from_std(net::UdpSocket::from(socket))
}
}

Expand Down Expand Up @@ -320,10 +320,10 @@ impl IntoRawSocket for UdpSocket {
}

#[cfg(windows)]
impl IntoSocket for UdpSocket {
impl From<UdpSocket> for OwnedSocket {
#[inline]
fn into_socket(self) -> OwnedSocket {
self.std.into_socket()
fn from(socket: UdpSocket) -> OwnedSocket {
self.std.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-std/src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use io_lifetimes::AsFilelike;
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
#[cfg(target_os = "wasi")]
use rustix::fs::OpenOptionsExt;
use std::io::{self, Read, Write};
Expand Down Expand Up @@ -709,10 +709,10 @@ impl FromRawHandle for Dir {
}

#[cfg(windows)]
impl FromHandle for Dir {
impl From<OwnedHandle> for Dir {
#[inline]
fn from_handle(handle: OwnedHandle) -> Self {
Self::from_std_file(fs::File::from_handle(handle))
fn from(handle: OwnedHandle) -> Self {
Self::from_std_file(fs::File::from(handle))
}
}

Expand Down Expand Up @@ -781,10 +781,10 @@ impl IntoRawHandle for Dir {
}

#[cfg(windows)]
impl IntoHandle for Dir {
impl From<Dir> for OwnedHandle {
#[inline]
fn into_handle(self) -> OwnedHandle {
self.std_file.into_handle()
fn from(dir: Dir) -> OwnedHandle {
dir.std_file.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-std/src/fs_utf8/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
use std::{fmt, fs, io};
#[cfg(windows)]
use {
Expand Down Expand Up @@ -646,12 +646,12 @@ impl FromRawHandle for Dir {
}

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

Expand Down Expand Up @@ -720,10 +720,10 @@ impl IntoRawHandle for Dir {
}

#[cfg(windows)]
impl IntoHandle for Dir {
impl From<Dir> for OwnedHandle {
#[inline]
fn into_handle(self) -> OwnedHandle {
self.cap_std.into_handle()
fn from(dir: Dir) -> OwnedHandle {
dir.cap_std.into()
}
}

Expand Down
14 changes: 7 additions & 7 deletions cap-std/src/fs_utf8/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
#[cfg(not(windows))]
use io_lifetimes::{AsFd, BorrowedFd, OwnedFd};
#[cfg(windows)]
use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle};
use io_lifetimes::{AsHandle, BorrowedHandle, OwnedHandle};
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
#[cfg(target_os = "wasi")]
use std::path::Path;
Expand Down Expand Up @@ -182,10 +182,10 @@ impl FromRawHandle for File {
}

#[cfg(windows)]
impl FromHandle for File {
impl From<OwnedHandle> for File {
#[inline]
fn from_handle(handle: OwnedHandle) -> Self {
Self::from_std(fs::File::from_handle(handle))
fn from(handle: OwnedHandle) -> Self {
Self::from_std(fs::File::from(handle))
}
}

Expand Down Expand Up @@ -254,10 +254,10 @@ impl IntoRawHandle for File {
}

#[cfg(windows)]
impl IntoHandle for File {
impl From<File> for OwnedHandle {
#[inline]
fn into_handle(self) -> OwnedHandle {
self.cap_std.into_handle()
fn from(file: File) -> OwnedHandle {
file.cap_std.into()
}
}

Expand Down
Loading

0 comments on commit 14af59c

Please sign in to comment.