-
Notifications
You must be signed in to change notification settings - Fork 13.4k
BorrowedFd::to_owned() gives you another BorrowedFd #88564
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Thanks for the report! Another option would be to remove the Is there a need for The reason I didn't add |
Hrm. Interesting. I haven't worked with this API much, so I don't feel I qualified to have an opinion. It does feel a bit odd, but I think it's going to be odd either way.
Err. I miswrote. I meant
I think anyone who is working with fds knows (ought to know) what the implications are. Obviously we should document that As for the "how you'd use this", I was just doing some work in Also, I think there are a number of places where APIs consumes an fd that could very helpfully take |
As suggested in rust-lang#88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code.
#88794 adds On removing Should we add
|
…r=joshtriplett Add a `try_clone()` function to `OwnedFd`. As suggested in rust-lang#88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code. r? `@joshtriplett`
…r=joshtriplett Add a `try_clone()` function to `OwnedFd`. As suggested in rust-lang#88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code. r? `@joshtriplett`
…r=joshtriplett Add a `try_clone()` function to `OwnedFd`. As suggested in rust-lang#88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code. r? ``@joshtriplett``
…r=joshtriplett Add a `try_clone()` function to `OwnedFd`. As suggested in rust-lang#88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code. r? `@joshtriplett`
…r=joshtriplett Add a `try_clone()` function to `OwnedFd`. As suggested in rust-lang#88564. This adds a `try_clone()` to `OwnedFd` by refactoring the code out of the existing `File`/`Socket` code. r? ``@joshtriplett``
Following up on rust-lang#88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`.
#88794 adding Thinking about So my inclination for this issue is to say that However, this is very much a judgement call, and I'm open to input here. |
…rrowedfd-toowned, r=joshtriplett Add documentation about `BorrowedFd::to_owned`. Following up on rust-lang#88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? `@joshtriplett`
…rrowedfd-toowned, r=joshtriplett Add documentation about `BorrowedFd::to_owned`. Following up on rust-lang#88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? ``@joshtriplett``
…rrowedfd-toowned, r=joshtriplett Add documentation about `BorrowedFd::to_owned`. Following up on rust-lang#88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? ```@joshtriplett```
…rrowedfd-toowned, r=joshtriplett Add documentation about `BorrowedFd::to_owned`. Following up on rust-lang#88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? ````@joshtriplett````
…rrowedfd-toowned, r=joshtriplett Add documentation about `BorrowedFd::to_owned`. Following up on rust-lang#88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? `````@joshtriplett`````
As mentioned in #93354, we looked at several options for what to do about #88794 added There isn't a |
…iplett Add a `BorrowedFd::try_clone_to_owned` and accompanying documentation Add a `BorrowedFd::try_clone_to_owned`, which returns a new `OwnedFd` sharing the underlying file description. And similar for `BorrowedHandle` and `BorrowedSocket` on WIndows. This is similar to the existing `OwnedFd::try_clone`, but it's named differently to reflect that it doesn't return `Result<Self, ...>`. I'm open to suggestions for better names. Also, extend the `unix::io` documentation to mention that `dup` is permitted on `BorrowedFd`. This was originally requsted [here](rust-lang#88564 (comment)). 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 a `BorrowedFd`, but the API only offered convenient ways to do it from an `OwnedFd`. With this patch, the API allows one to do `try_clone` on any type where it's permitted.
Add a `BorrowedFd::try_clone_to_owned` and accompanying documentation Add a `BorrowedFd::try_clone_to_owned`, which returns a new `OwnedFd` sharing the underlying file description. And similar for `BorrowedHandle` and `BorrowedSocket` on WIndows. This is similar to the existing `OwnedFd::try_clone`, but it's named differently to reflect that it doesn't return `Result<Self, ...>`. I'm open to suggestions for better names. Also, extend the `unix::io` documentation to mention that `dup` is permitted on `BorrowedFd`. This was originally requsted [here](rust-lang/rust#88564 (comment)). 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 a `BorrowedFd`, but the API only offered convenient ways to do it from an `OwnedFd`. With this patch, the API allows one to do `try_clone` on any type where it's permitted.
Firstly, I should say that I really like the basic ideas in RFC3128 (#87074) . I'm reporting a wrinkle which may or may not be soluble.
This program:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d51ddfa5a390e4d1b8f8bf81af8b0d73
Prints:
A naive reader might have thought it would print:
But of course converting a borrowed to an owned fd is fallible. And there is no
TryToOwned
. This no-opto_owned()
exists becauseBorrowedFd
isCopy
and thereforeClone
and eveyrhingClone
has a no-opToOwned
.The ideal fix from a type system and traits point of view (other than going back in time and abolishing the blanket
ToOwned for Clone
) would be forBorrowedFd
to somehow be a reference type. But it would have to actually be represented as an integer.pub struct BorrowableFdValue { x:() }
and transmutingc_int
viausize
to&BorrowableFdValue
and back would solve this but that is really quite stomach-churning (and the result can't be used in ffi the way the existingBorrowedFd
can).Maybe the answer is to simply document this quirk. We should probably provide
impl TryFrom<OwnedFd> from BorrowedFd
at the very least, and of courseOwnedFd::try_clone()
.The text was updated successfully, but these errors were encountered: