-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
std: Stabilize parts of std::os::platform::io #23766
Conversation
This commit stabilizes the platform-specific `io` modules, specifically around the traits having to do with the raw representation of each object on each platform. Specifically, the following material was stabilized: * `AsRaw{Fd,Socket,Handle}` * `RawFd` (renamed from `Fd`) * `RawHandle` (renamed from `Handle`) * `RawSocket` (renamed from `Socket`) * `AsRaw{Fd,Socket,Handle}` implementations * `std::os::{unix, windows}::io` The following material was added as `#[unstable]`: * `FromRaw{Fd,Socket,Handle}` * Implementations for various primitives There are a number of future improvements that are possible to make to this module, but this should cover a good bit of functionality desired from these modules for now. Some specific future additions may include: * `IntoRawXXX` traits to consume the raw representation and cancel the auto-destructor. * `Fd`, `Socket`, and `Handle` abstractions that behave like Rust objects and have nice methods for various syscalls. At this time though, these are considered backwards-compatible extensions and will not be stabilized at this time. This commit is a breaking change due to the addition of `Raw` in from of the type aliases in each of the platform-specific modules. [breaking-change]
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
r? @aturon |
Probably too late, but would this be better as Edit Changed to |
I agree with @carllerche, unless there are reasons for not going that route that I'm not aware of. Same with |
The problem with using the generic traits is that you lose any notion of "opt in" for platform-specific behavior. With traits defined in the platform modules, it's really clear from a |
@aturon Would you not get the "opt in" factor by pulling in the target types, like |
It depends partly on the specifics, but it's possible to write something like Regardless, the generic methods are not meant to fully replace named conversion methods; they're intended primarily for generic programming. |
Nice! It may be preferable to be the only owner of a A proper file descriptor ownership passing would save from file descriptor leaking. I prefer a trait-based pattern for The Probably the same for *Handle and *Socket. |
I fear that this may be overkill for this low-level method unfortunately. It seems like an extra "safety barrier" which may end up backfiring when you're in a situation like trying to get a file descriptor out of an
I fear that this is also perhaps too generalized for this use case. The trait is intended to represent the minimal step of construction from a file descriptor to an I/O object. It is in all cases currently just a noop, which is quite a powerful guarantee. The trait is intended to be an extension trait as well, not necessarily a general purpose trait. Along these lines I don't think we want to implement a conversion from something like I think any form of fallible conversion would also be done through a separate extension trait to clearly document why it may fail and be clear about what's going on. |
Replacing It leave the possibility to create your own |
|
Yes, you can, but only if you really want to. We should avoid |
Note that one of the primary points of these apis is that it does take ownership. In general we're not trying to create a one-size-fits-all "create this object from a file descriptor" abstraction, and erring on the side of being conservative is generally the better option for the standard library. Along these lines I think there's a few downsides to the two signatures you've proposed:
In general these APIs are the conservative option here as they are not designed to enable generic programming over |
I think we should move forward with this PR. While I agree with @l0kod that we will want to pursue safer abstractions in the long run, this lowest-level API will always have a place. This is part of the reason for shifting to "RawFd" naming everywhere -- we want to leave plenty of room to add a higher-level notion of |
⌛ Testing commit 6370f29 with merge 0a9618d... |
💔 Test failed - auto-mac-64-opt |
@bors: retry On Mon, Mar 30, 2015 at 5:13 PM, bors notifications@github.com wrote:
|
⌛ Testing commit 6370f29 with merge fce17ab... |
💔 Test failed - auto-mac-64-nopt-t |
@bors: retry |
This commit stabilizes the platform-specific `io` modules, specifically around the traits having to do with the raw representation of each object on each platform. Specifically, the following material was stabilized: * `AsRaw{Fd,Socket,Handle}` * `RawFd` (renamed from `Fd`) * `RawHandle` (renamed from `Handle`) * `RawSocket` (renamed from `Socket`) * `AsRaw{Fd,Socket,Handle}` implementations * `std::os::{unix, windows}::io` The following material was added as `#[unstable]`: * `FromRaw{Fd,Socket,Handle}` * Implementations for various primitives There are a number of future improvements that are possible to make to this module, but this should cover a good bit of functionality desired from these modules for now. Some specific future additions may include: * `IntoRawXXX` traits to consume the raw representation and cancel the auto-destructor. * `Fd`, `Socket`, and `Handle` abstractions that behave like Rust objects and have nice methods for various syscalls. At this time though, these are considered backwards-compatible extensions and will not be stabilized at this time. This commit is a breaking change due to the addition of `Raw` in from of the type aliases in each of the platform-specific modules. [breaking-change]
This commit stabilizes the platform-specific
io
modules, specifically aroundthe traits having to do with the raw representation of each object on each
platform.
Specifically, the following material was stabilized:
AsRaw{Fd,Socket,Handle}
RawFd
(renamed fromFd
)RawHandle
(renamed fromHandle
)RawSocket
(renamed fromSocket
)AsRaw{Fd,Socket,Handle}
implementationsstd::os::{unix, windows}::io
The following material was added as
#[unstable]
:FromRaw{Fd,Socket,Handle}
There are a number of future improvements that are possible to make to this
module, but this should cover a good bit of functionality desired from these
modules for now. Some specific future additions may include:
IntoRawXXX
traits to consume the raw representation and cancel theauto-destructor.
Fd
,Socket
, andHandle
abstractions that behave like Rust objects andhave nice methods for various syscalls.
At this time though, these are considered backwards-compatible extensions and
will not be stabilized at this time.
This commit is a breaking change due to the addition of
Raw
in from of thetype aliases in each of the platform-specific modules.
[breaking-change]