From d5314d4c52184aeda849d9e966bce5da0e9a7f69 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 23 Aug 2022 13:27:18 -0700 Subject: [PATCH] Update to io-lifetimes 1.0. This converts to the new traits, with `From` instead of `IntoFd` and `FromFd`. This currently depends on cap-async-std being disabled, since async-std doesn't yet have the io-safety trait impls yet. --- Cargo.toml | 4 +-- cap-async-std/Cargo.toml | 6 ++-- cap-async-std/src/fs/dir.rs | 14 +++++----- cap-async-std/src/fs/file.rs | 14 +++++----- cap-async-std/src/fs_utf8/dir.rs | 12 ++++---- cap-async-std/src/fs_utf8/file.rs | 12 ++++---- cap-async-std/src/net/tcp_listener.rs | 14 +++++----- cap-async-std/src/net/tcp_stream.rs | 14 +++++----- cap-async-std/src/net/udp_socket.rs | 14 +++++----- .../src/os/unix/net/unix_datagram.rs | 14 +++++----- .../src/os/unix/net/unix_listener.rs | 14 +++++----- cap-async-std/src/os/unix/net/unix_stream.rs | 14 +++++----- cap-directories/Cargo.toml | 2 +- cap-fs-ext/Cargo.toml | 2 +- cap-primitives/Cargo.toml | 8 +++--- .../src/rustix/fs/open_unchecked.rs | 4 +-- .../src/rustix/fs/read_dir_inner.rs | 10 +++---- cap-std/Cargo.toml | 6 ++-- cap-std/src/fs/dir.rs | 14 +++++----- cap-std/src/fs/file.rs | 28 +++++++++---------- cap-std/src/fs_utf8/dir.rs | 14 +++++----- cap-std/src/fs_utf8/file.rs | 14 +++++----- cap-std/src/net/tcp_listener.rs | 14 +++++----- cap-std/src/net/tcp_stream.rs | 14 +++++----- cap-std/src/net/udp_socket.rs | 14 +++++----- cap-std/src/os/unix/net/unix_datagram.rs | 14 +++++----- cap-std/src/os/unix/net/unix_listener.rs | 14 +++++----- cap-std/src/os/unix/net/unix_stream.rs | 14 +++++----- cap-tempfile/Cargo.toml | 2 +- cap-tempfile/src/tempfile.rs | 4 +-- cap-time-ext/Cargo.toml | 2 +- fuzz/Cargo.toml | 2 +- 32 files changed, 171 insertions(+), 171 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1f10c9324..568112aa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,10 @@ rand = "0.8.1" tempfile = "3.1.0" camino = "1.0.5" libc = "0.2.100" -io-lifetimes = "0.7.0" +io-lifetimes = "1.0.0-rc1" [target.'cfg(not(windows))'.dev-dependencies] -rustix = { version = "0.35.6", features = ["fs"] } +rustix = { version = "0.36.0-rc1", features = ["fs"] } [target.'cfg(windows)'.dev-dependencies] # nt_version uses internal Windows APIs, however we're only using it diff --git a/cap-async-std/Cargo.toml b/cap-async-std/Cargo.toml index de741783f..9331f7fc3 100644 --- a/cap-async-std/Cargo.toml +++ b/cap-async-std/Cargo.toml @@ -17,13 +17,13 @@ arf-strings = { version = "0.6.7", optional = true } # Enable "unstable" for `spawn_blocking`. async-std = { version = "1.10.0", features = ["attributes", "unstable"] } cap-primitives = { path = "../cap-primitives", version = "^0.25.0" } -io-lifetimes = { version = "0.7.0", default-features = false, features = ["async-std"] } +io-lifetimes = { version = "1.0.0-rc1", default-features = false, features = ["async-std"] } ipnet = "2.3.0" -io-extras = { version = "0.15.0", features = ["use_async_std"] } +io-extras = { version = "0.16.0-rc1", features = ["use_async_std"] } camino = { version = "1.0.5", optional = true } [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.35.6", features = ["fs"] } +rustix = { version = "0.36.0-rc1", features = ["fs"] } [features] default = [] diff --git a/cap-async-std/src/fs/dir.rs b/cap-async-std/src/fs/dir.rs index 16b220865..2a6ebbe08 100644 --- a/cap-async-std/src/fs/dir.rs +++ b/cap-async-std/src/fs/dir.rs @@ -14,7 +14,7 @@ use cap_primitives::fs::{ }; use cap_primitives::AmbientAuthority; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; use io_lifetimes::{AsFilelike, FromFilelike}; #[cfg(windows)] use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle}; @@ -869,10 +869,10 @@ impl FromRawFd for Dir { } #[cfg(not(windows))] -impl FromFd for Dir { +impl From for Dir { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std_file(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std_file(fs::File::from(fd)) } } @@ -943,10 +943,10 @@ impl IntoRawFd for Dir { } #[cfg(not(windows))] -impl IntoFd for Dir { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std_file.into_fd() + fn from(dir: Dir) -> OwnedFd { + dir.std_file.into() } } diff --git a/cap-async-std/src/fs/file.rs b/cap-async-std/src/fs/file.rs index 3f74794b8..d597391fc 100644 --- a/cap-async-std/src/fs/file.rs +++ b/cap-async-std/src/fs/file.rs @@ -10,7 +10,7 @@ use cap_primitives::fs::{is_file_read_write, open_ambient}; use cap_primitives::AmbientAuthority; use io_lifetimes::AsFilelike; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle}; use std::fmt; @@ -197,10 +197,10 @@ impl FromRawFd for File { } #[cfg(not(windows))] -impl FromFd for File { +impl From for File { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(fs::File::from(fd)) } } @@ -269,10 +269,10 @@ impl IntoRawFd for File { } #[cfg(not(windows))] -impl IntoFd for File { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(file: File) -> OwnedFd { + file.std.into() } } diff --git a/cap-async-std/src/fs_utf8/dir.rs b/cap-async-std/src/fs_utf8/dir.rs index e6d89edf1..6963eca98 100644 --- a/cap-async-std/src/fs_utf8/dir.rs +++ b/cap-async-std/src/fs_utf8/dir.rs @@ -644,10 +644,10 @@ impl FromRawFd for Dir { } #[cfg(not(windows))] -impl FromFd for Dir { +impl From for Dir { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std_file(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std_file(fs::File::from(fd)) } } @@ -718,10 +718,10 @@ impl IntoRawFd for Dir { } #[cfg(not(windows))] -impl IntoFd for Dir { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.cap_std.into_fd() + fn from(dir: Dir) -> OwnedFd { + dir.cap_std.into() } } diff --git a/cap-async-std/src/fs_utf8/file.rs b/cap-async-std/src/fs_utf8/file.rs index 2bbbb7e20..9cdd0f837 100644 --- a/cap-async-std/src/fs_utf8/file.rs +++ b/cap-async-std/src/fs_utf8/file.rs @@ -160,10 +160,10 @@ impl FromRawFd for File { } #[cfg(not(windows))] -impl FromFd for File { +impl From for File { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(fs::File::from(fd)) } } @@ -232,10 +232,10 @@ impl IntoRawFd for File { } #[cfg(not(windows))] -impl IntoFd for File { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.cap_std.into_fd() + fn from(file: File) -> OwnedFd { + file.cap_std.into() } } diff --git a/cap-async-std/src/net/tcp_listener.rs b/cap-async-std/src/net/tcp_listener.rs index 4ecd56e85..a8326cf7f 100644 --- a/cap-async-std/src/net/tcp_listener.rs +++ b/cap-async-std/src/net/tcp_listener.rs @@ -3,7 +3,7 @@ use crate::net::{Incoming, SocketAddr, TcpStream}; use async_std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use async_std::{io, net}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; use std::fmt; @@ -87,10 +87,10 @@ impl FromRawFd for TcpListener { } #[cfg(not(windows))] -impl FromFd for TcpListener { +impl From for TcpListener { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(net::TcpListener::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(net::TcpListener::from(fd)) } } @@ -159,10 +159,10 @@ impl IntoRawFd for TcpListener { } #[cfg(not(windows))] -impl IntoFd for TcpListener { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(listener: TcpListener) -> OwnedFd { + listener.std.into() } } diff --git a/cap-async-std/src/net/tcp_stream.rs b/cap-async-std/src/net/tcp_stream.rs index 453a30448..32e5cefb8 100644 --- a/cap-async-std/src/net/tcp_stream.rs +++ b/cap-async-std/src/net/tcp_stream.rs @@ -5,7 +5,7 @@ use async_std::net; use async_std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use async_std::task::{Context, Poll}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; use std::fmt; @@ -131,10 +131,10 @@ impl FromRawFd for TcpStream { } #[cfg(not(windows))] -impl FromFd for TcpStream { +impl From for TcpStream { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(net::TcpStream::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(net::TcpStream::from(fd)) } } @@ -203,10 +203,10 @@ impl IntoRawFd for TcpStream { } #[cfg(not(windows))] -impl IntoFd for TcpStream { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(stream: TcpStream) -> OwnedFd { + stream.std.into() } } diff --git a/cap-async-std/src/net/udp_socket.rs b/cap-async-std/src/net/udp_socket.rs index 7cd7d00bd..b3b9c0d66 100644 --- a/cap-async-std/src/net/udp_socket.rs +++ b/cap-async-std/src/net/udp_socket.rs @@ -3,7 +3,7 @@ use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; use async_std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use async_std::{io, net}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; use std::fmt; @@ -232,10 +232,10 @@ impl FromRawFd for UdpSocket { } #[cfg(not(windows))] -impl FromFd for UdpSocket { +impl From for UdpSocket { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(net::UdpSocket::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(net::UdpSocket::from(fd)) } } @@ -304,10 +304,10 @@ impl IntoRawFd for UdpSocket { } #[cfg(not(windows))] -impl IntoFd for UdpSocket { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(socket: UdpSocket) -> OwnedFd { + socket.std.into() } } diff --git a/cap-async-std/src/os/unix/net/unix_datagram.rs b/cap-async-std/src/os/unix/net/unix_datagram.rs index d3376f785..ac4872035 100644 --- a/cap-async-std/src/os/unix/net/unix_datagram.rs +++ b/cap-async-std/src/os/unix/net/unix_datagram.rs @@ -3,7 +3,7 @@ use crate::os::unix::net::SocketAddr; use async_std::io; use async_std::os::unix; use async_std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; use std::fmt; /// A Unix datagram socket. @@ -148,10 +148,10 @@ impl FromRawFd for UnixDatagram { } } -impl FromFd for UnixDatagram { +impl From for UnixDatagram { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(unix::net::UnixDatagram::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(unix::net::UnixDatagram::from(fd)) } } @@ -176,10 +176,10 @@ impl IntoRawFd for UnixDatagram { } } -impl IntoFd for UnixDatagram { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(datagram: UnixDatagram) -> OwnedFd { + datagram.std.into() } } diff --git a/cap-async-std/src/os/unix/net/unix_listener.rs b/cap-async-std/src/os/unix/net/unix_listener.rs index bf770ac4a..919167102 100644 --- a/cap-async-std/src/os/unix/net/unix_listener.rs +++ b/cap-async-std/src/os/unix/net/unix_listener.rs @@ -2,7 +2,7 @@ use crate::os::unix::net::{Incoming, SocketAddr, UnixStream}; use async_std::io; use async_std::os::unix; use async_std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; use std::fmt; /// A structure representing a Unix domain socket server. @@ -82,10 +82,10 @@ impl FromRawFd for UnixListener { } } -impl FromFd for UnixListener { +impl From for UnixListener { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(unix::net::UnixListener::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(unix::net::UnixListener::from(fd)) } } @@ -110,10 +110,10 @@ impl IntoRawFd for UnixListener { } } -impl IntoFd for UnixListener { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(listener: UnixListener) -> OwnedFd { + listener.std.into() } } diff --git a/cap-async-std/src/os/unix/net/unix_stream.rs b/cap-async-std/src/os/unix/net/unix_stream.rs index df6adeed0..79162d216 100644 --- a/cap-async-std/src/os/unix/net/unix_stream.rs +++ b/cap-async-std/src/os/unix/net/unix_stream.rs @@ -4,7 +4,7 @@ use async_std::io::{self, IoSlice, IoSliceMut, Read, Write}; use async_std::os::unix; use async_std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use async_std::task::{Context, Poll}; -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; use std::fmt; use std::pin::Pin; @@ -102,10 +102,10 @@ impl FromRawFd for UnixStream { } } -impl FromFd for UnixStream { +impl From for UnixStream { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(unix::net::UnixStream::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(unix::net::UnixStream::from(fd)) } } @@ -130,10 +130,10 @@ impl IntoRawFd for UnixStream { } } -impl IntoFd for UnixStream { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(stream: UnixStream) -> OwnedFd { + stream.std.into() } } diff --git a/cap-directories/Cargo.toml b/cap-directories/Cargo.toml index ef0cc133b..3b0fba76b 100644 --- a/cap-directories/Cargo.toml +++ b/cap-directories/Cargo.toml @@ -17,7 +17,7 @@ cap-std = { path = "../cap-std", version = "^0.25.0" } directories-next = "2.0.0" [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.35.6" } +rustix = { version = "0.36.0-rc1" } [target.'cfg(windows)'.dependencies.windows-sys] version = "0.36.0" diff --git a/cap-fs-ext/Cargo.toml b/cap-fs-ext/Cargo.toml index 3566e1a69..368dc6697 100644 --- a/cap-fs-ext/Cargo.toml +++ b/cap-fs-ext/Cargo.toml @@ -17,7 +17,7 @@ arf-strings = { version = "0.6.7", optional = true } #cap-async-std = { path = "../cap-async-std", optional = true, version = "^0.25.0" } cap-std = { path = "../cap-std", optional = true, version = "^0.25.0" } cap-primitives = { path = "../cap-primitives", version = "^0.25.0" } -io-lifetimes = { version = "0.7.0", default-features = false } +io-lifetimes = { version = "1.0.0-rc1", default-features = false } # Enable "unstable" for `spawn_blocking`. #async-std = { version = "1.10.0", features = ["attributes", "unstable"], optional = true } #async-trait = { version = "0.1.42", optional = true } diff --git a/cap-primitives/Cargo.toml b/cap-primitives/Cargo.toml index 3b452fb24..3cec20124 100644 --- a/cap-primitives/Cargo.toml +++ b/cap-primitives/Cargo.toml @@ -17,15 +17,15 @@ ambient-authority = "0.0.1" arbitrary = { version = "1.0.0", optional = true, features = ["derive"] } ipnet = "2.3.0" maybe-owned = "0.3.4" -fs-set-times = "0.17.0" -io-extras = "0.15.0" -io-lifetimes = { version = "0.7.0", default-features = false } +fs-set-times = "0.18.0-rc1" +io-extras = "0.16.0-rc1" +io-lifetimes = { version = "1.0.0-rc1", default-features = false } [dev-dependencies] cap-tempfile = { path = "../cap-tempfile" } [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.35.6", features = ["fs", "process", "procfs", "termios", "time"] } +rustix = { version = "0.36.0-rc1", features = ["fs", "process", "procfs", "termios", "time"] } [target.'cfg(windows)'.dependencies] winx = "0.33.0" diff --git a/cap-primitives/src/rustix/fs/open_unchecked.rs b/cap-primitives/src/rustix/fs/open_unchecked.rs index cf9bee6fd..4112a5a30 100644 --- a/cap-primitives/src/rustix/fs/open_unchecked.rs +++ b/cap-primitives/src/rustix/fs/open_unchecked.rs @@ -1,7 +1,7 @@ use super::compute_oflags; use crate::fs::{stat_unchecked, OpenOptions, OpenUncheckedError}; use crate::AmbientAuthority; -use io_lifetimes::{AsFilelike, FromFd}; +use io_lifetimes::AsFilelike; use rustix::fs::{cwd, openat, Mode}; use rustix::io; use std::fs; @@ -24,7 +24,7 @@ pub(crate) fn open_unchecked( let err = match openat(start, path, oflags, mode) { Ok(file) => { - return Ok(fs::File::from_fd(file.into())); + return Ok(fs::File::from(file)); } Err(err) => err, }; diff --git a/cap-primitives/src/rustix/fs/read_dir_inner.rs b/cap-primitives/src/rustix/fs/read_dir_inner.rs index 44f248a13..20626987d 100644 --- a/cap-primitives/src/rustix/fs/read_dir_inner.rs +++ b/cap-primitives/src/rustix/fs/read_dir_inner.rs @@ -4,9 +4,9 @@ use crate::fs::{ Metadata, OpenOptions, ReadDir, }; use io_extras::os::rustix::{AsRawFd, FromRawFd, RawFd}; -use io_lifetimes::{AsFd, IntoFd}; +use io_lifetimes::AsFd; +use rustix::fd::OwnedFd; use rustix::fs::Dir; -use rustix::io::OwnedFd; use std::ffi::OsStr; use std::mem::ManuallyDrop; #[cfg(unix)] @@ -32,7 +32,7 @@ impl ReadDirInner { let dir = Dir::read_from(fd.as_fd())?; Ok(Self { raw_fd: fd.as_fd().as_raw_fd(), - rustix: Arc::new(Mutex::new((dir, fd.into_fd().into()))), + rustix: Arc::new(Mutex::new((dir, OwnedFd::from(fd)))), }) } @@ -46,7 +46,7 @@ impl ReadDirInner { let dir = Dir::read_from(fd.as_fd())?; Ok(Self { raw_fd: fd.as_fd().as_raw_fd(), - rustix: Arc::new(Mutex::new((dir, fd.into_fd().into()))), + rustix: Arc::new(Mutex::new((dir, fd.into()))), }) } @@ -59,7 +59,7 @@ impl ReadDirInner { let dir = Dir::read_from(fd.as_fd())?; Ok(Self { raw_fd: fd.as_fd().as_raw_fd(), - rustix: Arc::new(Mutex::new((dir, fd.into_fd().into()))), + rustix: Arc::new(Mutex::new((dir, fd.into()))), }) } diff --git a/cap-std/Cargo.toml b/cap-std/Cargo.toml index b805fa987..8fb7d4bb8 100644 --- a/cap-std/Cargo.toml +++ b/cap-std/Cargo.toml @@ -20,12 +20,12 @@ rustdoc-args = ["--cfg=doc_cfg"] arf-strings = { version = "0.6.7", optional = true } cap-primitives = { path = "../cap-primitives", version = "^0.25.0" } ipnet = "2.3.0" -io-extras = "0.15.0" -io-lifetimes = { version = "0.7.0", default-features = false } +io-extras = "0.16.0-rc1" +io-lifetimes = { version = "1.0.0-rc1", default-features = false } camino = { version = "1.0.5", optional = true } [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.35.6", features = ["fs"] } +rustix = { version = "0.36.0-rc1", features = ["fs"] } [features] default = [] diff --git a/cap-std/src/fs/dir.rs b/cap-std/src/fs/dir.rs index f37dc5533..6312b8173 100644 --- a/cap-std/src/fs/dir.rs +++ b/cap-std/src/fs/dir.rs @@ -11,7 +11,7 @@ use cap_primitives::fs::{ use cap_primitives::AmbientAuthority; use io_lifetimes::AsFilelike; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle}; #[cfg(target_os = "wasi")] @@ -691,10 +691,10 @@ impl FromRawFd for Dir { } #[cfg(not(windows))] -impl FromFd for Dir { +impl From for Dir { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std_file(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std_file(fs::File::from(fd)) } } @@ -765,10 +765,10 @@ impl IntoRawFd for Dir { } #[cfg(not(windows))] -impl IntoFd for Dir { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std_file.into_fd() + fn from(dir: Dir) -> OwnedFd { + dir.std_file.into() } } diff --git a/cap-std/src/fs/file.rs b/cap-std/src/fs/file.rs index efb1a5d4d..0ca6b4a83 100644 --- a/cap-std/src/fs/file.rs +++ b/cap-std/src/fs/file.rs @@ -4,9 +4,9 @@ use cap_primitives::AmbientAuthority; #[cfg(not(windows))] use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +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}; use std::path::Path; use std::{fmt, fs, process}; @@ -167,10 +167,10 @@ impl FromRawFd for File { } #[cfg(not(windows))] -impl FromFd for File { +impl From for File { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(fs::File::from(fd)) } } @@ -183,10 +183,10 @@ impl FromRawHandle for File { } #[cfg(windows)] -impl FromHandle for File { +impl From 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)) } } @@ -239,10 +239,10 @@ impl IntoRawFd for File { } #[cfg(not(windows))] -impl IntoFd for File { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(file: File) -> OwnedFd { + file.std.into() } } @@ -255,10 +255,10 @@ impl IntoRawHandle for File { } #[cfg(windows)] -impl IntoHandle for File { +impl From for OwnedHandle { #[inline] - fn into_handle(self) -> OwnedHandle { - self.std.into_handle() + fn from(file: File) -> OwnedHandle { + file.std.into() } } diff --git a/cap-std/src/fs_utf8/dir.rs b/cap-std/src/fs_utf8/dir.rs index 533454e6f..1c0381676 100644 --- a/cap-std/src/fs_utf8/dir.rs +++ b/cap-std/src/fs_utf8/dir.rs @@ -7,7 +7,7 @@ use cap_primitives::AmbientAuthority; #[cfg(not(windows))] use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle}; use std::{fmt, fs, io}; @@ -628,10 +628,10 @@ impl FromRawFd for Dir { } #[cfg(not(windows))] -impl FromFd for Dir { +impl From for Dir { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std_file(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std_file(fs::File::from(fd)) } } @@ -704,10 +704,10 @@ impl IntoRawFd for Dir { } #[cfg(not(windows))] -impl IntoFd for Dir { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.cap_std.into_fd() + fn from(dir: Dir) -> OwnedFd { + dir.cap_std.into() } } diff --git a/cap-std/src/fs_utf8/file.rs b/cap-std/src/fs_utf8/file.rs index 8e5eb492d..b544ec7ce 100644 --- a/cap-std/src/fs_utf8/file.rs +++ b/cap-std/src/fs_utf8/file.rs @@ -5,7 +5,7 @@ use cap_primitives::AmbientAuthority; #[cfg(not(windows))] use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsHandle, BorrowedHandle, FromHandle, IntoHandle, OwnedHandle}; use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write}; @@ -166,10 +166,10 @@ impl FromRawFd for File { } #[cfg(not(windows))] -impl FromFd for File { +impl From for File { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(fs::File::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(fs::File::from(fd)) } } @@ -238,10 +238,10 @@ impl IntoRawFd for File { } #[cfg(not(windows))] -impl IntoFd for File { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.cap_std.into_fd() + fn from(file: File) -> OwnedFd { + file.cap_std.into() } } diff --git a/cap-std/src/net/tcp_listener.rs b/cap-std/src/net/tcp_listener.rs index cd476a04e..bb52d357e 100644 --- a/cap-std/src/net/tcp_listener.rs +++ b/cap-std/src/net/tcp_listener.rs @@ -2,7 +2,7 @@ use crate::net::{Incoming, SocketAddr, TcpStream}; #[cfg(not(windows))] use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; use std::{fmt, io, net}; @@ -116,10 +116,10 @@ impl FromRawFd for TcpListener { } #[cfg(not(windows))] -impl FromFd for TcpListener { +impl From for TcpListener { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(net::TcpListener::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(net::TcpListener::from(fd)) } } @@ -188,10 +188,10 @@ impl IntoRawFd for TcpListener { } #[cfg(not(windows))] -impl IntoFd for TcpListener { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(listener: TcpListener) -> OwnedFd { + listener.std.into() } } diff --git a/cap-std/src/net/tcp_stream.rs b/cap-std/src/net/tcp_stream.rs index f91230d5b..6e1c34352 100644 --- a/cap-std/src/net/tcp_stream.rs +++ b/cap-std/src/net/tcp_stream.rs @@ -2,7 +2,7 @@ use crate::net::{Shutdown, SocketAddr}; #[cfg(not(windows))] use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; use std::io::{self, IoSlice, IoSliceMut, Read, Write}; @@ -171,10 +171,10 @@ impl FromRawFd for TcpStream { } #[cfg(not(windows))] -impl FromFd for TcpStream { +impl From for TcpStream { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(net::TcpStream::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(net::TcpStream::from(fd)) } } @@ -243,10 +243,10 @@ impl IntoRawFd for TcpStream { } #[cfg(not(windows))] -impl IntoFd for TcpStream { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(stream: TcpStream) -> OwnedFd { + stream.std.into() } } diff --git a/cap-std/src/net/udp_socket.rs b/cap-std/src/net/udp_socket.rs index 13e6b15ce..9f39fa9ba 100644 --- a/cap-std/src/net/udp_socket.rs +++ b/cap-std/src/net/udp_socket.rs @@ -2,7 +2,7 @@ use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr}; #[cfg(not(windows))] use io_extras::os::rustix::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(not(windows))] -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; #[cfg(windows)] use io_lifetimes::{AsSocket, BorrowedSocket, FromSocket, IntoSocket, OwnedSocket}; use std::time::Duration; @@ -286,10 +286,10 @@ impl FromRawFd for UdpSocket { } #[cfg(not(windows))] -impl FromFd for UdpSocket { +impl From for UdpSocket { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(net::UdpSocket::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(net::UdpSocket::from(fd)) } } @@ -358,10 +358,10 @@ impl IntoRawFd for UdpSocket { } #[cfg(not(windows))] -impl IntoFd for UdpSocket { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(socket: UdpSocket) -> OwnedFd { + socket.std.into() } } diff --git a/cap-std/src/os/unix/net/unix_datagram.rs b/cap-std/src/os/unix/net/unix_datagram.rs index d46711fab..60d978cb0 100644 --- a/cap-std/src/os/unix/net/unix_datagram.rs +++ b/cap-std/src/os/unix/net/unix_datagram.rs @@ -1,6 +1,6 @@ use crate::net::Shutdown; use crate::os::unix::net::SocketAddr; -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; use std::os::unix; use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use std::time::Duration; @@ -203,10 +203,10 @@ impl FromRawFd for UnixDatagram { } } -impl FromFd for UnixDatagram { +impl From for UnixDatagram { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(unix::net::UnixDatagram::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(unix::net::UnixDatagram::from(fd)) } } @@ -231,10 +231,10 @@ impl IntoRawFd for UnixDatagram { } } -impl IntoFd for UnixDatagram { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(datagram: UnixDatagram) -> OwnedFd { + datagram.std.into() } } diff --git a/cap-std/src/os/unix/net/unix_listener.rs b/cap-std/src/os/unix/net/unix_listener.rs index 693668388..8ecf9aaa8 100644 --- a/cap-std/src/os/unix/net/unix_listener.rs +++ b/cap-std/src/os/unix/net/unix_listener.rs @@ -1,5 +1,5 @@ use crate::os::unix::net::{Incoming, SocketAddr, UnixStream}; -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; use std::os::unix; use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use std::{fmt, io}; @@ -103,10 +103,10 @@ impl FromRawFd for UnixListener { } } -impl FromFd for UnixListener { +impl From for UnixListener { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(unix::net::UnixListener::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(unix::net::UnixListener::from(fd)) } } @@ -131,10 +131,10 @@ impl IntoRawFd for UnixListener { } } -impl IntoFd for UnixListener { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(listener: UnixListener) -> OwnedFd { + listener.std.into() } } diff --git a/cap-std/src/os/unix/net/unix_stream.rs b/cap-std/src/os/unix/net/unix_stream.rs index 750019400..6894e0df7 100644 --- a/cap-std/src/os/unix/net/unix_stream.rs +++ b/cap-std/src/os/unix/net/unix_stream.rs @@ -1,6 +1,6 @@ use crate::net::Shutdown; use crate::os::unix::net::SocketAddr; -use io_lifetimes::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd}; +use io_lifetimes::{AsFd, BorrowedFd, OwnedFd}; use std::fmt; use std::io::{self, IoSlice, IoSliceMut, Read, Write}; use std::os::unix; @@ -157,10 +157,10 @@ impl FromRawFd for UnixStream { } } -impl FromFd for UnixStream { +impl From for UnixStream { #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_std(unix::net::UnixStream::from_fd(fd)) + fn from(fd: OwnedFd) -> Self { + Self::from_std(unix::net::UnixStream::from(fd)) } } @@ -185,10 +185,10 @@ impl IntoRawFd for UnixStream { } } -impl IntoFd for UnixStream { +impl From for OwnedFd { #[inline] - fn into_fd(self) -> OwnedFd { - self.std.into_fd() + fn from(stream: UnixStream) -> OwnedFd { + stream.std.into() } } diff --git a/cap-tempfile/Cargo.toml b/cap-tempfile/Cargo.toml index 68538e3fd..9855e8a64 100644 --- a/cap-tempfile/Cargo.toml +++ b/cap-tempfile/Cargo.toml @@ -21,7 +21,7 @@ camino = { version = "1.0.5", optional = true } rand = "0.8.1" [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.35.6", features = ["procfs"] } +rustix = { version = "0.36.0-rc1", features = ["procfs"] } [target.'cfg(windows)'.dev-dependencies.windows-sys] version = "0.36.0" diff --git a/cap-tempfile/src/tempfile.rs b/cap-tempfile/src/tempfile.rs index 320d7b83f..a9afab9f5 100644 --- a/cap-tempfile/src/tempfile.rs +++ b/cap-tempfile/src/tempfile.rs @@ -55,7 +55,7 @@ impl<'d> Debug for TempFile<'d> { #[cfg(any(target_os = "android", target_os = "linux"))] fn new_tempfile_linux(d: &Dir) -> io::Result> { - use rustix::fd::FromFd; + use cap_std::io_lifetimes::FromFd; use rustix::fs::{Mode, OFlags}; // openat's API uses WRONLY. There may be use cases for reading too, so let's support it. let oflags = OFlags::CLOEXEC | OFlags::TMPFILE | OFlags::RDWR; @@ -64,7 +64,7 @@ fn new_tempfile_linux(d: &Dir) -> io::Result> { let mode = Mode::from_raw_mode(0o666); // Happy path - Linux with O_TMPFILE match rustix::fs::openat(d, ".", oflags, mode) { - Ok(r) => return Ok(Some(File::from_fd(r.into()))), + Ok(r) => return Ok(Some(File::from_into_fd(r))), // See https://github.com/Stebalien/tempfile/blob/1a40687e06eb656044e3d2dffa1379f04b3ef3fd/src/file/imp/unix.rs#L81 // TODO: With newer Rust versions, this could be simplied to only write `Err` once. Err(rustix::io::Errno::OPNOTSUPP) diff --git a/cap-time-ext/Cargo.toml b/cap-time-ext/Cargo.toml index 8fa4df96e..9eca4aea8 100644 --- a/cap-time-ext/Cargo.toml +++ b/cap-time-ext/Cargo.toml @@ -17,7 +17,7 @@ cap-primitives = { path = "../cap-primitives", version = "^0.25.0" } cap-std = { path = "../cap-std", optional = true, version = "^0.25.0" } [target.'cfg(not(windows))'.dependencies] -rustix = { version = "0.35.6", features = ["time"] } +rustix = { version = "0.36.0-rc1", features = ["time"] } [target.'cfg(windows)'.dependencies] once_cell = "1.5.2" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 248ad5d46..c3aa52a91 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -15,7 +15,7 @@ cap-primitives = { path = "../cap-primitives", features = ["arbitrary"] } # Depend on io-lifetimes with default features, as the fuzzing framework # seems to add a dependency on `io_lifetimes::OwnedFd::drop` even when the # code itself doesn't have one. -io-lifetimes = "0.7.0" +io-lifetimes = "1.0.0-rc1" [[bin]] name = "cap-primitives"