-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implement AsFd
for &T
and &mut T
.
#93888
Merged
bors
merged 1 commit into
rust-lang:master
from
sunfishcode:sunfishcode/impl-asfd-for-ref
Feb 12, 2022
Merged
Implement AsFd
for &T
and &mut T
.
#93888
bors
merged 1 commit into
rust-lang:master
from
sunfishcode:sunfishcode/impl-asfd-for-ref
Feb 12, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add implementations of `AsFd` for `&T` and `&mut T`, so that users can write code like this: ```rust pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> { ``` with `fd: F` rather than `fd: &F`. And similar for `AsHandle` and `AsSocket` on Windows. Also, adjust the `fchown` example to pass the file by reference. The code can work either way now, but passing by reference is more likely to be what users will want to do. This is an alternative to rust-lang#93869, and is a simpler way to achieve the same goals: users don't need to pass borrowed-`BorrowedFd` arguments, and it prevents a pitfall in the case where users write `fd: F` instead of `fd: &F`.
rust-highfive
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
Feb 11, 2022
This looks like a great fix! @bors r+ |
📌 Commit 1f98ef7 has been approved by |
bors
added
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Feb 11, 2022
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 11, 2022
…or-ref, r=joshtriplett Implement `AsFd` for `&T` and `&mut T`. Add implementations of `AsFd` for `&T` and `&mut T`, so that users can write code like this: ```rust pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> { ``` with `fd: F` rather than `fd: &F`. And similar for `AsHandle` and `AsSocket` on Windows. Also, adjust the `fchown` example to pass the file by reference. The code can work either way now, but passing by reference is more likely to be what users will want to do. This is an alternative to rust-lang#93869, and is a simpler way to achieve the same goals: users don't need to pass borrowed-`BorrowedFd` arguments, and it prevents a pitfall in the case where users write `fd: F` instead of `fd: &F`. r? `@joshtriplett`
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 11, 2022
…or-ref, r=joshtriplett Implement `AsFd` for `&T` and `&mut T`. Add implementations of `AsFd` for `&T` and `&mut T`, so that users can write code like this: ```rust pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> { ``` with `fd: F` rather than `fd: &F`. And similar for `AsHandle` and `AsSocket` on Windows. Also, adjust the `fchown` example to pass the file by reference. The code can work either way now, but passing by reference is more likely to be what users will want to do. This is an alternative to rust-lang#93869, and is a simpler way to achieve the same goals: users don't need to pass borrowed-`BorrowedFd` arguments, and it prevents a pitfall in the case where users write `fd: F` instead of `fd: &F`. r? ``@joshtriplett``
sunfishcode
added a commit
to sunfishcode/io-lifetimes
that referenced
this pull request
Feb 11, 2022
This ports rust-lang/rust#93888 to io-lifetimes.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Feb 11, 2022
…askrgr Rollup of 10 pull requests Successful merges: - rust-lang#90955 (Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`) - rust-lang#91607 (Make `span_extend_to_prev_str()` more robust) - rust-lang#92895 (Remove some unused functionality) - rust-lang#93635 (Add missing platform-specific information on current_dir and set_current_dir) - rust-lang#93660 (rustdoc-json: Add some tests for typealias item) - rust-lang#93782 (Split `pauth` target feature) - rust-lang#93868 (Fix incorrect register conflict detection in asm!) - rust-lang#93888 (Implement `AsFd` for `&T` and `&mut T`.) - rust-lang#93909 (Fix typo: explicitely -> explicitly) - rust-lang#93910 (fix mention of moved function in `rustc_hir` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
sunfishcode
added a commit
to sunfishcode/io-lifetimes
that referenced
this pull request
Feb 15, 2022
This ports rust-lang/rust#93888 to io-lifetimes.
sunfishcode
added a commit
to bytecodealliance/rustix
that referenced
this pull request
Feb 16, 2022
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
sunfishcode
added a commit
to bytecodealliance/rustix
that referenced
this pull request
Feb 16, 2022
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
sunfishcode
added a commit
to bytecodealliance/rustix
that referenced
this pull request
Feb 17, 2022
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
sunfishcode
added a commit
to sunfishcode/io-extras
that referenced
this pull request
Feb 17, 2022
Update to io-lifetimes 0.5.2 and `impl AsFd for &T` support added in rust-lang/rust#93888 and sunfishcode/io-lifetimes#18.
sunfishcode
added a commit
to sunfishcode/io-extras
that referenced
this pull request
Feb 17, 2022
Update to io-lifetimes 0.5.2 and `impl AsFd for &T` support added in rust-lang/rust#93888 and sunfishcode/io-lifetimes#18.
This was referenced Feb 22, 2022
sunfishcode
added a commit
to sunfishcode/io-extras
that referenced
this pull request
Mar 15, 2022
Update to io-lifetimes 0.5.2 and `impl AsFd for &T` support added in rust-lang/rust#93888 and sunfishcode/io-lifetimes#18.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add implementations of
AsFd
for&T
and&mut T
, so that users canwrite code like this:
with
fd: F
rather thanfd: &F
.And similar for
AsHandle
andAsSocket
on Windows.Also, adjust the
fchown
example to pass the file by reference. Thecode can work either way now, but passing by reference is more likely
to be what users will want to do.
This is an alternative to #93869, and is a simpler way to achieve the
same goals: users don't need to pass borrowed-
BorrowedFd
arguments,and it prevents a pitfall in the case where users write
fd: F
insteadof
fd: &F
.r? @joshtriplett