From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/io-lifetimes/src/impls_std.rs | 888 +++++++++++++++++++++++++++++++++++ 1 file changed, 888 insertions(+) create mode 100644 vendor/io-lifetimes/src/impls_std.rs (limited to 'vendor/io-lifetimes/src/impls_std.rs') diff --git a/vendor/io-lifetimes/src/impls_std.rs b/vendor/io-lifetimes/src/impls_std.rs new file mode 100644 index 000000000..27275fa68 --- /dev/null +++ b/vendor/io-lifetimes/src/impls_std.rs @@ -0,0 +1,888 @@ +#[cfg(any(unix, target_os = "wasi"))] +use crate::{AsFd, FromFd, IntoFd}; +#[cfg(windows)] +use crate::{AsHandle, AsSocket, FromHandle, FromSocket, IntoHandle, IntoSocket}; +#[cfg(any(unix, target_os = "wasi"))] +use crate::{BorrowedFd, OwnedFd}; +#[cfg(windows)] +use crate::{BorrowedHandle, BorrowedSocket, HandleOrInvalid, OwnedHandle, OwnedSocket}; +#[cfg(unix)] +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(target_os = "wasi")] +use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::io::{ + AsRawHandle, AsRawSocket, FromRawHandle, FromRawSocket, IntoRawHandle, IntoRawSocket, +}; + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for BorrowedFd<'_> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for BorrowedHandle<'_> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsSocket for BorrowedSocket<'_> { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for OwnedFd { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for OwnedHandle { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsSocket for OwnedSocket { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for OwnedFd { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { Self::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for OwnedHandle { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { Self::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl IntoSocket for OwnedSocket { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { Self::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for OwnedFd { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for OwnedHandle { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl FromSocket for OwnedSocket { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl FromHandle for HandleOrInvalid { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for HandleOrInvalid { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::fs::File { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::fs::File { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::fs::File { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for OwnedFd { + #[inline] + fn from(owned: std::fs::File) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::fs::File { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for OwnedHandle { + #[inline] + fn from(owned: std::fs::File) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::fs::File { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for std::fs::File { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for std::fs::File { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for std::fs::File { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::net::TcpStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for std::net::TcpStream { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::net::TcpStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for OwnedFd { + #[inline] + fn from(owned: std::net::TcpStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for std::net::TcpStream { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From for OwnedSocket { + #[inline] + fn from(owned: std::net::TcpStream) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::net::TcpStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for std::net::TcpStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for std::net::TcpStream { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From for std::net::TcpStream { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::net::TcpListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for std::net::TcpListener { + #[inline] + fn as_socket(&self) -> BorrowedSocket<'_> { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::net::TcpListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for OwnedFd { + #[inline] + fn from(owned: std::net::TcpListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for std::net::TcpListener { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From for OwnedSocket { + #[inline] + fn from(owned: std::net::TcpListener) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::net::TcpListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for std::net::TcpListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for std::net::TcpListener { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From for std::net::TcpListener { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::net::UdpSocket { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsSocket for std::net::UdpSocket { + #[inline] + fn as_socket(&self) -> BorrowedSocket { + unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl IntoFd for std::net::UdpSocket { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for OwnedFd { + #[inline] + fn from(owned: std::net::UdpSocket) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoSocket for std::net::UdpSocket { + #[inline] + fn into_socket(self) -> OwnedSocket { + unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From for OwnedSocket { + #[inline] + fn from(owned: std::net::UdpSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl FromFd for std::net::UdpSocket { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl From for std::net::UdpSocket { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromSocket for std::net::UdpSocket { + #[inline] + fn from_socket(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(windows)] +impl From for std::net::UdpSocket { + #[inline] + fn from(owned: OwnedSocket) -> Self { + unsafe { Self::from_raw_socket(owned.into_raw_socket()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::io::Stdin { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::io::Stdin { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<'a> AsFd for std::io::StdinLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl<'a> AsHandle for std::io::StdinLock<'a> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::io::Stdout { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::io::Stdout { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<'a> AsFd for std::io::StdoutLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl<'a> AsHandle for std::io::StdoutLock<'a> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl AsFd for std::io::Stderr { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::io::Stderr { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(any(unix, target_os = "wasi"))] +impl<'a> AsFd for std::io::StderrLock<'a> { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl<'a> AsHandle for std::io::StderrLock<'a> { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::process::ChildStdin { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::ChildStdin { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::process::ChildStdin { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for OwnedFd { + #[inline] + fn from(owned: std::process::ChildStdin) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::ChildStdin { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for OwnedHandle { + #[inline] + fn from(owned: std::process::ChildStdin) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::process::ChildStdout { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::ChildStdout { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::process::ChildStdout { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for OwnedFd { + #[inline] + fn from(owned: std::process::ChildStdout) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::ChildStdout { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for OwnedHandle { + #[inline] + fn from(owned: std::process::ChildStdout) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::process::ChildStderr { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::ChildStderr { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::process::ChildStderr { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for OwnedFd { + #[inline] + fn from(owned: std::process::ChildStderr) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::ChildStderr { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for OwnedHandle { + #[inline] + fn from(owned: std::process::ChildStderr) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl FromFd for std::process::Stdio { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for std::process::Stdio { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl FromHandle for std::process::Stdio { + #[inline] + fn from_handle(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for std::process::Stdio { + #[inline] + fn from(owned: OwnedHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::process::Child { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::process::Child { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From for OwnedHandle { + #[inline] + fn from(owned: std::process::Child) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} + +#[cfg(unix)] +impl AsFd for std::os::unix::net::UnixStream { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::os::unix::net::UnixStream { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for OwnedFd { + #[inline] + fn from(owned: std::os::unix::net::UnixStream) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for std::os::unix::net::UnixStream { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for std::os::unix::net::UnixStream { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl AsFd for std::os::unix::net::UnixListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::os::unix::net::UnixListener { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for OwnedFd { + #[inline] + fn from(owned: std::os::unix::net::UnixListener) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for std::os::unix::net::UnixListener { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for std::os::unix::net::UnixListener { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl AsFd for std::os::unix::net::UnixDatagram { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } + } +} + +#[cfg(unix)] +impl IntoFd for std::os::unix::net::UnixDatagram { + #[inline] + fn into_fd(self) -> OwnedFd { + unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for OwnedFd { + #[inline] + fn from(owned: std::os::unix::net::UnixDatagram) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl FromFd for std::os::unix::net::UnixDatagram { + #[inline] + fn from_fd(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(unix)] +impl From for std::os::unix::net::UnixDatagram { + #[inline] + fn from(owned: OwnedFd) -> Self { + unsafe { Self::from_raw_fd(owned.into_raw_fd()) } + } +} + +#[cfg(windows)] +impl AsHandle for std::thread::JoinHandle { + #[inline] + fn as_handle(&self) -> BorrowedHandle<'_> { + unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } + } +} + +#[cfg(windows)] +impl IntoHandle for std::thread::JoinHandle { + #[inline] + fn into_handle(self) -> OwnedHandle { + unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } + } +} + +#[cfg(windows)] +impl From> for OwnedHandle { + #[inline] + fn from(owned: std::thread::JoinHandle) -> Self { + unsafe { Self::from_raw_handle(owned.into_raw_handle()) } + } +} -- cgit v1.2.3