Skip to content

Commit

Permalink
Change impl trait arguments to explicit generic parameters. (#1283)
Browse files Browse the repository at this point in the history
As discussed [here], use generic parameters instead of impl trait
argumentst.

[here]: #753 (comment)
  • Loading branch information
sunfishcode authored Jan 25, 2025
1 parent ce43fdd commit 8270a91
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 42 deletions.
20 changes: 12 additions & 8 deletions src/event/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ pub fn create(flags: epoll::CreateFlags) -> io::Result<OwnedFd> {
/// [faq]: https://man7.org/linux/man-pages/man7/epoll.7.html#:~:text=Will%20closing%20a%20file%20descriptor%20cause%20it%20to%20be%20removed%20from%20all%0A%20%20%20%20%20%20%20%20%20%20epoll%20interest%20lists%3F
#[doc(alias = "epoll_ctl")]
#[inline]
pub fn add(
epoll: impl AsFd,
source: impl AsFd,
pub fn add<EpollFd: AsFd, SourceFd: AsFd>(
epoll: EpollFd,
source: SourceFd,
data: epoll::EventData,
event_flags: epoll::EventFlags,
) -> io::Result<()> {
Expand Down Expand Up @@ -154,9 +154,9 @@ pub fn add(
/// [illumos]: https://www.illumos.org/man/3C/epoll_ctl
#[doc(alias = "epoll_ctl")]
#[inline]
pub fn modify(
epoll: impl AsFd,
source: impl AsFd,
pub fn modify<EpollFd: AsFd, SourceFd: AsFd>(
epoll: EpollFd,
source: SourceFd,
data: epoll::EventData,
event_flags: epoll::EventFlags,
) -> io::Result<()> {
Expand All @@ -183,7 +183,7 @@ pub fn modify(
/// [illumos]: https://www.illumos.org/man/3C/epoll_ctl
#[doc(alias = "epoll_ctl")]
#[inline]
pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
pub fn delete<EpollFd: AsFd, SourceFd: AsFd>(epoll: EpollFd, source: SourceFd) -> io::Result<()> {
syscalls::epoll_del(epoll.as_fd(), source.as_fd())
}

Expand All @@ -202,7 +202,11 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc"), alias = "epoll_wait"))]
#[inline]
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
pub fn wait<EpollFd: AsFd>(
epoll: EpollFd,
event_list: &mut EventVec,
timeout: c::c_int,
) -> io::Result<()> {
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
// behaves.
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/event/kqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ pub fn kqueue() -> io::Result<OwnedFd> {
/// [OpenBSD]: https://man.openbsd.org/kevent.2
/// [NetBSD]: https://man.netbsd.org/kevent.2
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=kevent&section=2
pub unsafe fn kevent(
kqueue: impl AsFd,
pub unsafe fn kevent<Fd: AsFd>(
kqueue: Fd,
changelist: &[Event],
eventlist: &mut Vec<Event>,
timeout: Option<Duration>,
Expand Down
21 changes: 12 additions & 9 deletions src/event/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ pub fn port_create() -> io::Result<OwnedFd> {
///
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_associate/
/// [illumos]: https://illumos.org/man/3C/port_associate
pub unsafe fn port_associate_fd(
port: impl AsFd,
object: impl AsRawFd,
pub unsafe fn port_associate_fd<Fd: AsFd, RawFd: AsRawFd>(
port: Fd,
object: RawFd,
events: PollFlags,
userdata: *mut ffi::c_void,
) -> io::Result<()> {
Expand All @@ -87,7 +87,10 @@ pub unsafe fn port_associate_fd(
///
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_dissociate
/// [illumos]: https://illumos.org/man/3C/port_dissociate
pub unsafe fn port_dissociate_fd(port: impl AsFd, object: impl AsRawFd) -> io::Result<()> {
pub unsafe fn port_dissociate_fd<Fd: AsFd, RawFd: AsRawFd>(
port: Fd,
object: RawFd,
) -> io::Result<()> {
syscalls::port_dissociate(port.as_fd(), c::PORT_SOURCE_FD, object.as_raw_fd() as _)
}

Expand All @@ -99,7 +102,7 @@ pub unsafe fn port_dissociate_fd(port: impl AsFd, object: impl AsRawFd) -> io::R
///
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_get/
/// [illumos]: https://illumos.org/man/3C/port_get
pub fn port_get(port: impl AsFd, timeout: Option<Duration>) -> io::Result<Event> {
pub fn port_get<Fd: AsFd>(port: Fd, timeout: Option<Duration>) -> io::Result<Event> {
let mut timeout = timeout.map(|timeout| c::timespec {
tv_sec: timeout.as_secs().try_into().unwrap(),
tv_nsec: timeout.subsec_nanos() as _,
Expand All @@ -125,8 +128,8 @@ pub fn port_get(port: impl AsFd, timeout: Option<Duration>) -> io::Result<Event>
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_getn/
/// [illumos]: https://illumos.org/man/3C/port_getn
#[cfg(feature = "alloc")]
pub fn port_getn(
port: impl AsFd,
pub fn port_getn<Fd: AsFd>(
port: Fd,
events: &mut Vec<Event>,
min_events: usize,
timeout: Option<Duration>,
Expand Down Expand Up @@ -157,7 +160,7 @@ pub fn port_getn(
///
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_getn/
/// [illumos]: https://illumos.org/man/3C/port_getn
pub fn port_getn_query(port: impl AsFd) -> io::Result<u32> {
pub fn port_getn_query<Fd: AsFd>(port: Fd) -> io::Result<u32> {
syscalls::port_getn_query(port.as_fd())
}

Expand All @@ -169,6 +172,6 @@ pub fn port_getn_query(port: impl AsFd) -> io::Result<u32> {
///
/// [OpenSolaris]: https://www.unix.com/man-page/opensolaris/3C/port_send/
/// [illumos]: https://illumos.org/man/3C/port_send
pub fn port_send(port: impl AsFd, events: i32, userdata: *mut ffi::c_void) -> io::Result<()> {
pub fn port_send<Fd: AsFd>(port: Fd, events: i32, userdata: *mut ffi::c_void) -> io::Result<()> {
syscalls::port_send(port.as_fd(), events, userdata.cast())
}
6 changes: 3 additions & 3 deletions src/fs/inotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub fn init(flags: inotify::CreateFlags) -> io::Result<OwnedFd> {
/// application should keep track of this externally to avoid logic errors.
#[doc(alias = "inotify_add_watch")]
#[inline]
pub fn add_watch<P: crate::path::Arg>(
inot: impl AsFd,
pub fn add_watch<P: crate::path::Arg, Fd: AsFd>(
inot: Fd,
path: P,
flags: inotify::WatchFlags,
) -> io::Result<i32> {
Expand All @@ -85,7 +85,7 @@ pub fn add_watch<P: crate::path::Arg>(
/// [`inotify::add_watch`] and not previously have been removed.
#[doc(alias = "inotify_rm_watch")]
#[inline]
pub fn remove_watch(inot: impl AsFd, wd: i32) -> io::Result<()> {
pub fn remove_watch<Fd: AsFd>(inot: Fd, wd: i32) -> io::Result<()> {
syscalls::inotify_rm_watch(inot.as_fd(), wd)
}

Expand Down
4 changes: 2 additions & 2 deletions src/net/netdevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use alloc::string::String;
/// [Linux]: https://man7.org/linux/man-pages/man7/netdevice.7.html
#[inline]
#[doc(alias = "SIOCGIFINDEX")]
pub fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
pub fn name_to_index<Fd: AsFd>(fd: Fd, if_name: &str) -> io::Result<u32> {
crate::backend::net::netdevice::name_to_index(fd, if_name)
}

Expand All @@ -50,7 +50,7 @@ pub fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
#[inline]
#[doc(alias = "SIOCGIFNAME")]
#[cfg(feature = "alloc")]
pub fn index_to_name(fd: impl AsFd, index: u32) -> io::Result<String> {
pub fn index_to_name<Fd: AsFd>(fd: Fd, index: u32) -> io::Result<String> {
crate::backend::net::netdevice::index_to_name(fd, index)
}

Expand Down
28 changes: 14 additions & 14 deletions src/net/send_recv/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ impl FusedIterator for AncillaryDrain<'_> {}
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
#[inline]
pub fn sendmsg(
socket: impl AsFd,
pub fn sendmsg<Fd: AsFd>(
socket: Fd,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
flags: SendFlags,
Expand Down Expand Up @@ -647,8 +647,8 @@ pub fn sendmsg(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
#[inline]
pub fn sendmsg_v4(
socket: impl AsFd,
pub fn sendmsg_v4<Fd: AsFd>(
socket: Fd,
addr: &SocketAddrV4,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
Expand Down Expand Up @@ -678,8 +678,8 @@ pub fn sendmsg_v4(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
#[inline]
pub fn sendmsg_v6(
socket: impl AsFd,
pub fn sendmsg_v6<Fd: AsFd>(
socket: Fd,
addr: &SocketAddrV6,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
Expand Down Expand Up @@ -711,8 +711,8 @@ pub fn sendmsg_v6(
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
#[inline]
#[cfg(unix)]
pub fn sendmsg_unix(
socket: impl AsFd,
pub fn sendmsg_unix<Fd: AsFd>(
socket: Fd,
addr: &super::SocketAddrUnix,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
Expand All @@ -729,8 +729,8 @@ pub fn sendmsg_unix(
/// [Linux]: https://man7.org/linux/man-pages/man2/sendmsg.2.html
#[inline]
#[cfg(target_os = "linux")]
pub fn sendmsg_xdp(
socket: impl AsFd,
pub fn sendmsg_xdp<Fd: AsFd>(
socket: Fd,
addr: &super::SocketAddrXdp,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
Expand Down Expand Up @@ -760,8 +760,8 @@ pub fn sendmsg_xdp(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
#[inline]
pub fn sendmsg_any(
socket: impl AsFd,
pub fn sendmsg_any<Fd: AsFd>(
socket: Fd,
addr: Option<&SocketAddrAny>,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
Expand Down Expand Up @@ -807,8 +807,8 @@ pub fn sendmsg_any(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=recvmsg&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/recvmsg
#[inline]
pub fn recvmsg(
socket: impl AsFd,
pub fn recvmsg<Fd: AsFd>(
socket: Fd,
iov: &mut [IoSliceMut<'_>],
control: &mut RecvAncillaryBuffer<'_>,
flags: RecvFlags,
Expand Down
6 changes: 4 additions & 2 deletions src/process/prctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,10 @@ const PR_PAC_SET_ENABLED_KEYS: c_int = 60;
/// [`prctl(PR_PAC_SET_ENABLED_KEYS,…)`]: https://www.kernel.org/doc/html/v6.10/arch/arm64/pointer-authentication.html
#[inline]
#[doc(alias = "PR_PAC_SET_ENABLED_KEYS")]
pub unsafe fn configure_pointer_authentication_keys(
config: impl Iterator<Item = (PointerAuthenticationKeys, bool)>,
pub unsafe fn configure_pointer_authentication_keys<
Config: Iterator<Item = (PointerAuthenticationKeys, bool)>,
>(
config: Config,
) -> io::Result<()> {
let mut affected_keys: u32 = 0;
let mut enabled_keys: u32 = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/process/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ pub fn wait(waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> {
/// state.
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "wasi")))]
#[inline]
pub fn waitid<'a>(
id: impl Into<WaitId<'a>>,
pub fn waitid<'a, Id: Into<WaitId<'a>>>(
id: Id,
options: WaitIdOptions,
) -> io::Result<Option<WaitIdStatus>> {
backend::process::syscalls::waitid(id.into(), options)
Expand Down

0 comments on commit 8270a91

Please sign in to comment.