-
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
Add a BorrowedFd::try_clone_to_owned
and accompanying documentation
#97178
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
As an example use case, |
r? @joshtriplett for sign-off on the new API |
impl BorrowedFd<'_> { | ||
/// Creates a new `OwnedFd` instance that shares the same underlying file | ||
/// description as the existing `BorrowedFd` instance. | ||
#[cfg(not(target_arch = "wasm32"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does WASI not have a dup function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not, today. Because of all the descriptor vs. description issues, the original WASI left dup
out to give itself flexibility to figure out what it wanted to say. Today we now have a clear sense of how we want this to work, and I expect WASI will add a dup
. When it does, we can remove this code from Rust.
👍 for adding this, modulo the question about WASI. @bors d+ Go ahead and merge when ready, though you may want to wait to avoid conflict with the in-flight stabilization. |
☔ The latest upstream changes (presumably #98131) made this pull request unmergeable. Please resolve the merge conflicts. |
And `BorrowedHandle::try_clone_to_owned` and `BorrowedSocket::try_clone_to_owned` on Windows.
On Unix, describe these in terms of the underlying "file description". On Windows, describe them in terms of the underlying "object".
5a2b4c8
to
007cbfd
Compare
This comment has been minimized.
This comment has been minimized.
I've answered the WASI question above, and fixed the merge conflict. @bors r+ |
@sunfishcode: 🔑 Insufficient privileges: Not in reviewers |
@bors r=sunfishcode |
@sunfishcode: 🔑 Insufficient privileges: Not in reviewers |
@bors r=joshtriplett |
📌 Commit ee49d65 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b31f9cc): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
Add a
BorrowedFd::try_clone_to_owned
, which returns a newOwnedFd
sharing the underlying file description. And similar forBorrowedHandle
andBorrowedSocket
on WIndows.This is similar to the existing
OwnedFd::try_clone
, but it's named differently to reflect that it doesn't returnResult<Self, ...>
. I'm open to suggestions for better names.Also, extend the
unix::io
documentation to mention thatdup
is permitted onBorrowedFd
.This was originally requsted here. At the time I wasn't sure whether it was desirable, but it does have uses and it helps clarify the API. The documentation previously didn't rule out using
dup
on aBorrowedFd
, but the API only offered convenient ways to do it from anOwnedFd
. With this patch, the API allows one to dotry_clone
on any type where it's permitted.