impl<T: AsFd> AsFd for {Arc,Box}<T>
This commit is contained in:
parent
ed1e3512dc
commit
cf483a130c
@ -355,3 +355,34 @@ fn from(owned_fd: OwnedFd) -> Self {
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
||||
#[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 @@ fn as_raw_fd(&self) -> RawFd {
|
||||
}
|
||||
}
|
||||
|
||||
#[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 @@ fn as_raw_fd(&self) -> RawFd {
|
||||
}
|
||||
}
|
||||
|
||||
#[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…
Reference in New Issue
Block a user