Reduce impl trait by using macro in raw_fd.rs
This commit is contained in:
parent
53791b3ff4
commit
1869141e54
1 changed files with 31 additions and 58 deletions
|
@ -2,66 +2,39 @@ use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
||||||
use crate::sys_common::{self, AsInner, FromInner, IntoInner};
|
use crate::sys_common::{self, AsInner, FromInner, IntoInner};
|
||||||
use crate::{net, sys};
|
use crate::{net, sys};
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
macro_rules! impl_as_raw_fd {
|
||||||
impl AsRawFd for net::TcpStream {
|
($($t:ident)*) => {$(
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
*self.as_inner().socket().as_inner()
|
impl AsRawFd for net::$t {
|
||||||
}
|
fn as_raw_fd(&self) -> RawFd {
|
||||||
|
*self.as_inner().socket().as_inner()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*};
|
||||||
}
|
}
|
||||||
|
impl_as_raw_fd! { TcpStream TcpListener UdpSocket }
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
macro_rules! impl_from_raw_fd {
|
||||||
impl AsRawFd for net::TcpListener {
|
($($t:ident)*) => {$(
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||||
*self.as_inner().socket().as_inner()
|
impl FromRawFd for net::$t {
|
||||||
}
|
unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
|
||||||
|
let socket = sys::net::Socket::from_inner(fd);
|
||||||
|
net::$t::from_inner(sys_common::net::$t::from_inner(socket))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*};
|
||||||
}
|
}
|
||||||
|
impl_from_raw_fd! { TcpStream TcpListener UdpSocket }
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
macro_rules! impl_into_raw_fd {
|
||||||
impl AsRawFd for net::UdpSocket {
|
($($t:ident)*) => {$(
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
||||||
*self.as_inner().socket().as_inner()
|
impl IntoRawFd for net::$t {
|
||||||
}
|
fn into_raw_fd(self) -> RawFd {
|
||||||
}
|
self.into_inner().into_socket().into_inner()
|
||||||
|
}
|
||||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
}
|
||||||
impl FromRawFd for net::TcpStream {
|
)*};
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
|
|
||||||
let socket = sys::net::Socket::from_inner(fd);
|
|
||||||
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
|
||||||
impl FromRawFd for net::TcpListener {
|
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
|
|
||||||
let socket = sys::net::Socket::from_inner(fd);
|
|
||||||
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
|
||||||
impl FromRawFd for net::UdpSocket {
|
|
||||||
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
|
|
||||||
let socket = sys::net::Socket::from_inner(fd);
|
|
||||||
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
|
||||||
impl IntoRawFd for net::TcpStream {
|
|
||||||
fn into_raw_fd(self) -> RawFd {
|
|
||||||
self.into_inner().into_socket().into_inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
|
||||||
impl IntoRawFd for net::TcpListener {
|
|
||||||
fn into_raw_fd(self) -> RawFd {
|
|
||||||
self.into_inner().into_socket().into_inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
|
||||||
impl IntoRawFd for net::UdpSocket {
|
|
||||||
fn into_raw_fd(self) -> RawFd {
|
|
||||||
self.into_inner().into_socket().into_inner()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
impl_into_raw_fd! { TcpStream TcpListener UdpSocket }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue