Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new impl AsFd for &T support in io-lifetimes. #232

Merged
merged 3 commits into from
Feb 17, 2022

Conversation

sunfishcode
Copy link
Member

With rust-lang/rust#93888 now in nightly, and sunfishcode/io-lifetimes#18 now
in io-lifetimes 0.5.2, we can now simplify the AsFd pattern from
fn foo<Fd: AsFd>(fd: &Fd) to fn foo<Fd: AsFd>(fd: Fd), without the &.

This also follows the emerging convention in std, as seen in the new
fchown function.

This means that users can now pass BorrowedFd values directly to
functions that expect AsFd arguments, without having to write an
extra & when passing them.

With rust-lang/rust#93888 now in nightly, and sunfishcode/io-lifetimes#18 now
in io-lifetimes 0.5.2, we can now simplify the `AsFd` pattern from
`fn foo<Fd: AsFd>(fd: &Fd)` to `fn foo<Fd: AsFd>(fd: Fd)`, without the `&`.

This also follows the emerging convention in std, as seen in the new
[`fchown`] function.

This means that users can now pass `BorrowedFd` values directly to
functions that expect `AsFd` arguments, without having to write an
extra `&` when passing them.

[`fchown`]: https://doc.rust-lang.org/nightly/std/os/unix/fs/fn.fchown.html
…is-terminal`.

is-terminal is implemented in terms of rustix, so the code was
previously just testing rustix against itself, and creating an awkward
circluar dependency besides.

Test against `libc::isatty` and `ioctl_tiocgwinsz` instead.
Copy link
Contributor

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, this looks a lot better! I was confused by the need to & a BorrowedFd indeed.

@sunfishcode sunfishcode merged commit 26b3481 into main Feb 17, 2022
@sunfishcode sunfishcode deleted the sunfishcode/asfd-ref branch February 17, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants