impl<T: AsFd> AsFd for {Arc,Box}<T>
This commit is contained in:
parent
ed1e3512dc
commit
cf483a130c
2 changed files with 33 additions and 3 deletions
|
@ -355,3 +355,34 @@ impl From<OwnedFd> for crate::net::UdpSocket {
|
|||
))))
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "io_safety", since = "1.63.0")]
|
||||
/// This impl allows implementing traits that require `AsFd` on Arc.
|
||||
/// ```
|
||||
/// # #[cfg(any(unix, target_os = "wasi"))] mod group_cfg {
|
||||
/// # #[cfg(target_os = "wasi")]
|
||||
/// # use std::os::wasi::io::AsFd;
|
||||
/// # #[cfg(unix)]
|
||||
/// # use std::os::unix::io::AsFd;
|
||||
/// use std::net::UdpSocket;
|
||||
/// use std::sync::Arc;
|
||||
///
|
||||
/// trait MyTrait: AsFd {}
|
||||
/// impl MyTrait for Arc<UdpSocket> {}
|
||||
/// impl MyTrait for Box<UdpSocket> {}
|
||||
/// # }
|
||||
/// ```
|
||||
impl<T: AsFd> AsFd for crate::sync::Arc<T> {
|
||||
#[inline]
|
||||
fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
(**self).as_fd()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "io_safety", since = "1.63.0")]
|
||||
impl<T: AsFd> AsFd for Box<T> {
|
||||
#[inline]
|
||||
fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
(**self).as_fd()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,8 +223,7 @@ impl<'a> AsRawFd for io::StderrLock<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_ptrs", since = "1.63.0")]
|
||||
/// This blanket impl allows implementing custom traits that require `AsRawFd` on Arc.
|
||||
/// This impl allows implementing traits that require `AsRawFd` on Arc.
|
||||
/// ```
|
||||
/// # #[cfg(any(unix, target_os = "wasi"))] mod group_cfg {
|
||||
/// # #[cfg(target_os = "wasi")]
|
||||
|
@ -247,7 +246,7 @@ impl<T: AsRawFd> AsRawFd for crate::sync::Arc<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "asraw_ptrs", since = "1.63.0")]
|
||||
#[stable(feature = "asrawfd_ptrs", since = "1.63.0")]
|
||||
impl<T: AsRawFd> AsRawFd for Box<T> {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue