diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index b53c3e79b0fe6..da81fc87ee20f 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -177,7 +177,7 @@ impl fmt::Debug for OwnedFd { /// call the method. Windows platforms have a corresponding `AsHandle` and /// `AsSocket` set of traits. #[unstable(feature = "io_safety", issue = "87074")] -pub trait AsFd { +pub trait AsFd<'a> { /// Borrows the file descriptor. /// /// # Example @@ -197,21 +197,21 @@ pub trait AsFd { /// # Ok::<(), io::Error>(()) /// ``` #[unstable(feature = "io_safety", issue = "87074")] - fn as_fd(&self) -> BorrowedFd<'_>; + fn as_fd(self) -> BorrowedFd<'a>; } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for BorrowedFd<'_> { +impl<'a> AsFd<'a> for &'a BorrowedFd<'_> { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { *self } } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for OwnedFd { +impl<'a> AsFd<'a> for &'a OwnedFd { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { // Safety: `OwnedFd` and `BorrowedFd` have the same validity // invariants, and the `BorrowdFd` is bounded by the lifetime // of `&self`. @@ -220,9 +220,9 @@ impl AsFd for OwnedFd { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for fs::File { +impl<'a> AsFd<'a> for &'a fs::File { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().as_fd() } } @@ -244,9 +244,9 @@ impl From for fs::File { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for crate::net::TcpStream { +impl<'a> AsFd<'a> for &'a crate::net::TcpStream { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().socket().as_fd() } } @@ -270,9 +270,9 @@ impl From for crate::net::TcpStream { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for crate::net::TcpListener { +impl<'a> AsFd<'a> for &'a crate::net::TcpListener { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().socket().as_fd() } } @@ -296,9 +296,9 @@ impl From for crate::net::TcpListener { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for crate::net::UdpSocket { +impl<'a> AsFd<'a> for &'a crate::net::UdpSocket { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().socket().as_fd() } } diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 540363c03494e..ca9624ca5207e 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -87,8 +87,8 @@ impl IntoRawFd for PidFd { } } -impl AsFd for PidFd { - fn as_fd(&self) -> BorrowedFd<'_> { +impl<'a> AsFd<'a> for &'a PidFd { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().as_fd() } } diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs index db7edcd057432..760d6d1a02784 100644 --- a/library/std/src/os/unix/fs.rs +++ b/library/std/src/os/unix/fs.rs @@ -966,12 +966,12 @@ pub fn chown>(dir: P, uid: Option, gid: Option) -> io:: /// /// fn main() -> std::io::Result<()> { /// let f = std::fs::File::open("/file")?; -/// fs::fchown(f, Some(0), Some(0))?; +/// fs::fchown(&f, Some(0), Some(0))?; /// Ok(()) /// } /// ``` #[unstable(feature = "unix_chown", issue = "88989")] -pub fn fchown(fd: F, uid: Option, gid: Option) -> io::Result<()> { +pub fn fchown<'a, F: AsFd<'a>>(fd: F, uid: Option, gid: Option) -> io::Result<()> { sys::fs::fchown(fd.as_fd().as_raw_fd(), uid.unwrap_or(u32::MAX), gid.unwrap_or(u32::MAX)) } diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index a2caccc784917..489e5381d9e08 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -1008,9 +1008,9 @@ impl IntoRawFd for UnixDatagram { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for UnixDatagram { +impl<'a> AsFd<'a> for &'a UnixDatagram { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.0.as_inner().as_fd() } } diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index b23dd6062f682..418abc1479587 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -301,9 +301,9 @@ impl IntoRawFd for UnixListener { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for UnixListener { +impl<'a> AsFd<'a> for &'a UnixListener { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.0.as_inner().as_fd() } } diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 583f861a92535..ebabd2ddce57c 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -707,9 +707,9 @@ impl IntoRawFd for UnixStream { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for UnixStream { +impl<'a> AsFd<'a> for &'a UnixStream { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.0.as_fd() } } diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index 855f900430c4a..267b6ecf2174a 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -388,9 +388,9 @@ impl IntoRawFd for process::ChildStderr { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for crate::process::ChildStdin { +impl<'a> AsFd<'a> for &'a crate::process::ChildStdin { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().as_fd() } } @@ -404,9 +404,9 @@ impl From for OwnedFd { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for crate::process::ChildStdout { +impl<'a> AsFd<'a> for &'a crate::process::ChildStdout { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().as_fd() } } @@ -420,9 +420,9 @@ impl From for OwnedFd { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for crate::process::ChildStderr { +impl<'a> AsFd<'a> for &'a crate::process::ChildStderr { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { self.as_inner().as_fd() } } diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index e37ce633a129a..bad8a09d9af25 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -298,7 +298,7 @@ impl fmt::Debug for OwnedHandle { /// A trait to borrow the handle from an underlying object. #[unstable(feature = "io_safety", issue = "87074")] -pub trait AsHandle { +pub trait AsHandle<'a> { /// Borrows the handle. /// /// # Example @@ -313,19 +313,19 @@ pub trait AsHandle { /// let borrowed_handle: BorrowedHandle<'_> = f.as_handle(); /// # Ok::<(), io::Error>(()) /// ``` - fn as_handle(&self) -> BorrowedHandle<'_>; + fn as_handle(self) -> BorrowedHandle<'a>; } -impl AsHandle for BorrowedHandle<'_> { +impl<'a> AsHandle<'a> for &'a BorrowedHandle<'_> { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { *self } } -impl AsHandle for OwnedHandle { +impl<'a> AsHandle<'a> for &'a OwnedHandle { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { // Safety: `OwnedHandle` and `BorrowedHandle` have the same validity // invariants, and the `BorrowdHandle` is bounded by the lifetime // of `&self`. @@ -333,9 +333,9 @@ impl AsHandle for OwnedHandle { } } -impl AsHandle for fs::File { +impl<'a> AsHandle<'a> for &'a fs::File { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { self.as_inner().as_handle() } } @@ -354,51 +354,51 @@ impl From for fs::File { } } -impl AsHandle for crate::io::Stdin { +impl<'a> AsHandle<'a> for &'a crate::io::Stdin { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } -impl<'a> AsHandle for crate::io::StdinLock<'a> { +impl<'a, 'b> AsHandle<'a> for &'a crate::io::StdinLock<'b> { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } -impl AsHandle for crate::io::Stdout { +impl<'a> AsHandle<'a> for &'a crate::io::Stdout { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } -impl<'a> AsHandle for crate::io::StdoutLock<'a> { +impl<'a, 'b> AsHandle<'a> for &'a crate::io::StdoutLock<'b> { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } -impl AsHandle for crate::io::Stderr { +impl<'a> AsHandle<'a> for &'a crate::io::Stderr { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } -impl<'a> AsHandle for crate::io::StderrLock<'a> { +impl<'a, 'b> AsHandle<'a> for &'a crate::io::StderrLock<'b> { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } -impl AsHandle for crate::process::ChildStdin { +impl<'a> AsHandle<'a> for &'a crate::process::ChildStdin { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } @@ -410,9 +410,9 @@ impl From for OwnedHandle { } } -impl AsHandle for crate::process::ChildStdout { +impl<'a> AsHandle<'a> for &'a crate::process::ChildStdout { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } @@ -424,9 +424,9 @@ impl From for OwnedHandle { } } -impl AsHandle for crate::process::ChildStderr { +impl<'a> AsHandle<'a> for &'a crate::process::ChildStderr { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } @@ -438,9 +438,9 @@ impl From for OwnedHandle { } } -impl AsHandle for crate::thread::JoinHandle { +impl<'a, T> AsHandle<'a> for &'a crate::thread::JoinHandle { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { unsafe { BorrowedHandle::borrow_raw_handle(self.as_raw_handle()) } } } diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index d3a5b6dcc76c6..e0cfdc8aa8c33 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -205,21 +205,21 @@ impl fmt::Debug for OwnedSocket { /// A trait to borrow the socket from an underlying object. #[unstable(feature = "io_safety", issue = "87074")] -pub trait AsSocket { +pub trait AsSocket<'a> { /// Borrows the socket. - fn as_socket(&self) -> BorrowedSocket<'_>; + fn as_socket(self) -> BorrowedSocket<'a>; } -impl AsSocket for BorrowedSocket<'_> { +impl<'a> AsSocket<'a> for &'a BorrowedSocket<'_> { #[inline] - fn as_socket(&self) -> BorrowedSocket<'_> { + fn as_socket(self) -> BorrowedSocket<'a> { *self } } -impl AsSocket for OwnedSocket { +impl<'a> AsSocket<'a> for &'a OwnedSocket { #[inline] - fn as_socket(&self) -> BorrowedSocket<'_> { + fn as_socket(self) -> BorrowedSocket<'a> { // Safety: `OwnedSocket` and `BorrowedSocket` have the same validity // invariants, and the `BorrowdSocket` is bounded by the lifetime // of `&self`. @@ -227,9 +227,9 @@ impl AsSocket for OwnedSocket { } } -impl AsSocket for crate::net::TcpStream { +impl<'a> AsSocket<'a> for &'a crate::net::TcpStream { #[inline] - fn as_socket(&self) -> BorrowedSocket<'_> { + fn as_socket(self) -> BorrowedSocket<'a> { unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) } } } @@ -248,9 +248,9 @@ impl From for crate::net::TcpStream { } } -impl AsSocket for crate::net::TcpListener { +impl<'a> AsSocket<'a> for &'a crate::net::TcpListener { #[inline] - fn as_socket(&self) -> BorrowedSocket<'_> { + fn as_socket(self) -> BorrowedSocket<'a> { unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) } } } @@ -269,9 +269,9 @@ impl From for crate::net::TcpListener { } } -impl AsSocket for crate::net::UdpSocket { +impl<'a> AsSocket<'a> for &'a crate::net::UdpSocket { #[inline] - fn as_socket(&self) -> BorrowedSocket<'_> { + fn as_socket(self) -> BorrowedSocket<'a> { unsafe { BorrowedSocket::borrow_raw_socket(self.as_raw_socket()) } } } diff --git a/library/std/src/os/windows/process.rs b/library/std/src/os/windows/process.rs index 9510d104806db..87b60c0249069 100644 --- a/library/std/src/os/windows/process.rs +++ b/library/std/src/os/windows/process.rs @@ -40,9 +40,9 @@ impl AsRawHandle for process::Child { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsHandle for process::Child { +impl<'a> AsHandle<'a> for &'a process::Child { #[inline] - fn as_handle(&self) -> BorrowedHandle<'_> { + fn as_handle(self) -> BorrowedHandle<'a> { self.as_inner().handle().as_handle() } } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index 3de7c68a6866d..1894d244f956d 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -289,8 +289,8 @@ impl FromInner for FileDesc { } } -impl AsFd for FileDesc { - fn as_fd(&self) -> BorrowedFd<'_> { +impl<'a> AsFd<'a> for &'a FileDesc { + fn as_fd(self) -> BorrowedFd<'a> { self.0.as_fd() } } diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs index 8bd0b9b14afed..7c8438ab38b69 100644 --- a/library/std/src/sys/unix/fs.rs +++ b/library/std/src/sys/unix/fs.rs @@ -983,13 +983,15 @@ impl FromInner for File { } } -impl AsFd for File { - fn as_fd(&self) -> BorrowedFd<'_> { +impl File { + pub fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } } impl AsRawFd for File { + /// Similar to `AsFd::as_fd`, but doesn't require `File` to have + /// stability attributes. fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 61c15ecd85de3..b5d3acf3c00d6 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -461,13 +461,15 @@ impl FromInner for Socket { } } -impl AsFd for Socket { - fn as_fd(&self) -> BorrowedFd<'_> { +impl Socket { + pub fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } } impl AsRawFd for Socket { + /// Similar to `AsFd::as_fd`, but doesn't require `Socket` to have + /// stability attributes. fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() } diff --git a/library/std/src/sys/unix/pipe.rs b/library/std/src/sys/unix/pipe.rs index a56c275c94207..4947dc0cbdb23 100644 --- a/library/std/src/sys/unix/pipe.rs +++ b/library/std/src/sys/unix/pipe.rs @@ -132,8 +132,10 @@ impl AsRawFd for AnonPipe { } } -impl AsFd for AnonPipe { - fn as_fd(&self) -> BorrowedFd<'_> { +impl AnonPipe { + /// Similar to `AsFd::as_fd`, but doesn't require `AnonPipe` to have + /// stability attributes. + pub fn as_fd(&self) -> BorrowedFd<'_> { self.0.as_fd() } } diff --git a/library/std/src/sys/unix/stdio.rs b/library/std/src/sys/unix/stdio.rs index b359987595d30..3694d9dece9b8 100644 --- a/library/std/src/sys/unix/stdio.rs +++ b/library/std/src/sys/unix/stdio.rs @@ -93,49 +93,49 @@ pub fn panic_output() -> Option { } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for io::Stdin { +impl<'a> AsFd<'a> for &'a io::Stdin { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { unsafe { BorrowedFd::borrow_raw_fd(libc::STDIN_FILENO) } } } #[unstable(feature = "io_safety", issue = "87074")] -impl<'a> AsFd for io::StdinLock<'a> { +impl<'a, 'b> AsFd<'a> for io::StdinLock<'b> { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { unsafe { BorrowedFd::borrow_raw_fd(libc::STDIN_FILENO) } } } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for io::Stdout { +impl<'a> AsFd<'a> for &'a io::Stdout { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { unsafe { BorrowedFd::borrow_raw_fd(libc::STDOUT_FILENO) } } } #[unstable(feature = "io_safety", issue = "87074")] -impl<'a> AsFd for io::StdoutLock<'a> { +impl<'a, 'b> AsFd<'a> for &'a io::StdoutLock<'b> { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { unsafe { BorrowedFd::borrow_raw_fd(libc::STDOUT_FILENO) } } } #[unstable(feature = "io_safety", issue = "87074")] -impl AsFd for io::Stderr { +impl<'a> AsFd<'a> for &'a io::Stderr { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { unsafe { BorrowedFd::borrow_raw_fd(libc::STDERR_FILENO) } } } #[unstable(feature = "io_safety", issue = "87074")] -impl<'a> AsFd for io::StderrLock<'a> { +impl<'a, 'b> AsFd<'a> for &'a io::StderrLock<'b> { #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { + fn as_fd(self) -> BorrowedFd<'a> { unsafe { BorrowedFd::borrow_raw_fd(libc::STDERR_FILENO) } } } diff --git a/library/std/src/sys/wasi/fd.rs b/library/std/src/sys/wasi/fd.rs index 0b9c8e61db84c..6343a12edf775 100644 --- a/library/std/src/sys/wasi/fd.rs +++ b/library/std/src/sys/wasi/fd.rs @@ -282,8 +282,8 @@ impl FromInner for WasiFd { } } -impl AsFd for WasiFd { - fn as_fd(&self) -> BorrowedFd<'_> { +impl<'a> AsFd<'a> for &'a WasiFd { + fn as_fd(self) -> BorrowedFd<'a> { self.fd.as_fd() } } diff --git a/library/std/src/sys/wasi/fs.rs b/library/std/src/sys/wasi/fs.rs index cd6815bfc2136..4f988e0b257b0 100644 --- a/library/std/src/sys/wasi/fs.rs +++ b/library/std/src/sys/wasi/fs.rs @@ -482,8 +482,8 @@ impl FromInner for File { } } -impl AsFd for File { - fn as_fd(&self) -> BorrowedFd<'_> { +impl<'a> AsFd<'a> for &'a File { + fn as_fd(self) -> BorrowedFd<'a> { self.fd.as_fd() } } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index c66e0e4d328ad..b8573aa317528 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -35,8 +35,8 @@ impl FromInner for Socket { } } -impl AsFd for Socket { - fn as_fd(&self) -> BorrowedFd<'_> { +impl<'a> AsFd<'a> for &'a Socket { + fn as_fd(self) -> BorrowedFd<'a> { self.0.as_fd() } } diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index cb83ee2469a1c..225ea1ea4fab2 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -784,8 +784,10 @@ impl FromInner for File { } } -impl AsHandle for File { - fn as_handle(&self) -> BorrowedHandle<'_> { +impl File { + /// Similar to `AsHandle::as_handle`, but doesn't require `File` to have + /// stability attributes. + pub fn as_handle(&self) -> BorrowedHandle<'_> { self.as_inner().as_handle() } } diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs index daab39bb00cbc..252ad2c082f23 100644 --- a/library/std/src/sys/windows/handle.rs +++ b/library/std/src/sys/windows/handle.rs @@ -48,8 +48,8 @@ impl FromInner for Handle { } } -impl AsHandle for Handle { - fn as_handle(&self) -> BorrowedHandle<'_> { +impl<'a> AsHandle<'a> for &'a Handle { + fn as_handle(self) -> BorrowedHandle<'a> { self.0.as_handle() } } diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index aa6400aeefa0d..89149a626973a 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -451,8 +451,8 @@ impl IntoInner for Socket { } } -impl AsSocket for Socket { - fn as_socket(&self) -> BorrowedSocket<'_> { +impl<'a> AsSocket<'a> for &'a Socket { + fn as_socket(self) -> BorrowedSocket<'a> { self.0.as_socket() } }