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

Implement AsRawFd/IntoRawFd for RawFd #40842

Merged
merged 1 commit into from
Mar 31, 2017
Merged

Implement AsRawFd/IntoRawFd for RawFd #40842

merged 1 commit into from
Mar 31, 2017

Conversation

Mic92
Copy link
Contributor

@Mic92 Mic92 commented Mar 26, 2017

This is useful to build os abstraction like the nix crate does.
It allows to define functions, which accepts generic arguments
of data structures convertible to RawFd, including RawFd itself.
For example:

fn write<FD: AsRawFd>(fd: FD, buf: &[u8]) -> Result<usize>
write(file, buf);

instead of:

fn write(fd: RawFd, buf: &[u8]) -> Result<usize>
write(file.as_raw_fd(), buf);

cc @kamalmarhubi

This is useful to build os abstraction like the nix crate does.
It allows to define functions, which accepts generic arguments
of data structures convertible to RawFd, including RawFd itself.
For example:

  fn write<FD: AsRawFd>(fd: FD, buf: &[u8]) -> Result<usize>

instead of:

  fn write(fd: RawFd, buf: &[u8]) -> Result<usize>
  write(foo.as_raw_fd(), buf);
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@@ -73,6 +73,13 @@ pub trait IntoRawFd {
}

#[stable(feature = "rust1", since = "1.0.0")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not familiar with the internal feature flags and what is appropriate here.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 27, 2017
@aturon
Copy link
Member

aturon commented Mar 29, 2017

Thanks @Mic92! This looks great.

Regarding stability: trait impls are not tracked for stability anyway, so what you have here is just fine.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 29, 2017

📌 Commit 2cf686f has been approved by aturon

@bors
Copy link
Contributor

bors commented Mar 30, 2017

⌛ Testing commit 2cf686f with merge 131a125...

@bors
Copy link
Contributor

bors commented Mar 30, 2017

💔 Test failed - status-appveyor

@aturon
Copy link
Member

aturon commented Mar 30, 2017

Spurious failure, logged at #40240

@bors: retry

@bors
Copy link
Contributor

bors commented Mar 30, 2017

⌛ Testing commit 2cf686f with merge d9d7931...

@bors
Copy link
Contributor

bors commented Mar 30, 2017

💔 Test failed - status-appveyor

@aturon
Copy link
Member

aturon commented Mar 30, 2017

@bors: retry

(This appveyor failure has been resolved)

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 31, 2017
Implement AsRawFd/IntoRawFd for RawFd

This is useful to build os abstraction like the nix crate does.
It allows to define functions, which accepts generic arguments
of data structures convertible to RawFd, including RawFd itself.
For example:

```
fn write<FD: AsRawFd>(fd: FD, buf: &[u8]) -> Result<usize>
write(file, buf);
```
instead of:
```
fn write(fd: RawFd, buf: &[u8]) -> Result<usize>
write(file.as_raw_fd(), buf);
```

cc @kamalmarhubi
bors added a commit that referenced this pull request Mar 31, 2017
Rollup of 10 pull requests

- Successful merges: #40694, #40842, #40869, #40888, #40898, #40904, #40925, #40928, #40929, #40934
- Failed merges:
@bors bors merged commit 2cf686f into rust-lang:master Mar 31, 2017
@Mic92 Mic92 deleted the RawFd branch March 31, 2017 19:54
@codyps
Copy link
Contributor

codyps commented Apr 2, 2017

Because RawFd is just a type alias for c_int, which is just a type alias for i32 (or similar), this actually adds impls for AsRawFd and IntoRawFd for i32 (or similar).

https://is.gd/2vZEiW

This doesn't necessarily seem like a good idea as APIs that previously relied on AsRawFd and IntoRawFd returning a valid RawFd can no longer rely on the Fd being valid.

codyps added a commit to codyps/rust that referenced this pull request Apr 3, 2017
This reverts commit 2cf686f (rust-lang#40842)

RawFd is a type alias for c_int, which is itself a type alias for i32.
As a result, adding AsRawFd and IntoRawFd impls for RawFd actually adds
them for i32.

As a result, the reverted commit makes this valid:

```
use std::os::unix::io::AsRawFd;

fn arf<T: AsRawFd>(_: T) {}

fn main() {
    arf(32i32)
}
```

Implimenting AsRawFd and IntoRawFd for i32 breaks the promises of both
those traits that their methods return a valid RawFd.

r? @aturon
cc @Mic92 @kamalmarhubi
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 3, 2017
…aturon

Revert "Implement AsRawFd/IntoRawFd for RawFd"

This reverts commit 2cf686f (rust-lang#40842)

RawFd is a type alias for c_int, which is itself a type alias for i32.
As a result, adding AsRawFd and IntoRawFd impls for RawFd actually adds
them for i32.

As a result, the reverted commit makes this valid:

```
use std::os::unix::io::AsRawFd;

fn arf<T: AsRawFd>(_: T) {}

fn main() {
    arf(32i32)
}
```

Implimenting AsRawFd and IntoRawFd for i32 breaks the promises of both
those traits that their methods return a valid RawFd.

r? @aturon
cc @Mic92 @kamalmarhubi
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 3, 2017
…aturon

Revert "Implement AsRawFd/IntoRawFd for RawFd"

This reverts commit 2cf686f (rust-lang#40842)

RawFd is a type alias for c_int, which is itself a type alias for i32.
As a result, adding AsRawFd and IntoRawFd impls for RawFd actually adds
them for i32.

As a result, the reverted commit makes this valid:

```
use std::os::unix::io::AsRawFd;

fn arf<T: AsRawFd>(_: T) {}

fn main() {
    arf(32i32)
}
```

Implimenting AsRawFd and IntoRawFd for i32 breaks the promises of both
those traits that their methods return a valid RawFd.

r? @aturon
cc @Mic92 @kamalmarhubi
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 4, 2017
…aturon

Revert "Implement AsRawFd/IntoRawFd for RawFd"

This reverts commit 2cf686f (rust-lang#40842)

RawFd is a type alias for c_int, which is itself a type alias for i32.
As a result, adding AsRawFd and IntoRawFd impls for RawFd actually adds
them for i32.

As a result, the reverted commit makes this valid:

```
use std::os::unix::io::AsRawFd;

fn arf<T: AsRawFd>(_: T) {}

fn main() {
    arf(32i32)
}
```

Implimenting AsRawFd and IntoRawFd for i32 breaks the promises of both
those traits that their methods return a valid RawFd.

r? @aturon
cc @Mic92 @kamalmarhubi
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 4, 2017
…aturon

Revert "Implement AsRawFd/IntoRawFd for RawFd"

This reverts commit 2cf686f (rust-lang#40842)

RawFd is a type alias for c_int, which is itself a type alias for i32.
As a result, adding AsRawFd and IntoRawFd impls for RawFd actually adds
them for i32.

As a result, the reverted commit makes this valid:

```
use std::os::unix::io::AsRawFd;

fn arf<T: AsRawFd>(_: T) {}

fn main() {
    arf(32i32)
}
```

Implimenting AsRawFd and IntoRawFd for i32 breaks the promises of both
those traits that their methods return a valid RawFd.

r? @aturon
cc @Mic92 @kamalmarhubi
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 5, 2017
…aturon

Revert "Implement AsRawFd/IntoRawFd for RawFd"

This reverts commit 2cf686f (rust-lang#40842)

RawFd is a type alias for c_int, which is itself a type alias for i32.
As a result, adding AsRawFd and IntoRawFd impls for RawFd actually adds
them for i32.

As a result, the reverted commit makes this valid:

```
use std::os::unix::io::AsRawFd;

fn arf<T: AsRawFd>(_: T) {}

fn main() {
    arf(32i32)
}
```

Implimenting AsRawFd and IntoRawFd for i32 breaks the promises of both
those traits that their methods return a valid RawFd.

r? @aturon
cc @Mic92 @kamalmarhubi
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 5, 2017
…aturon

Revert "Implement AsRawFd/IntoRawFd for RawFd"

This reverts commit 2cf686f (rust-lang#40842)

RawFd is a type alias for c_int, which is itself a type alias for i32.
As a result, adding AsRawFd and IntoRawFd impls for RawFd actually adds
them for i32.

As a result, the reverted commit makes this valid:

```
use std::os::unix::io::AsRawFd;

fn arf<T: AsRawFd>(_: T) {}

fn main() {
    arf(32i32)
}
```

Implimenting AsRawFd and IntoRawFd for i32 breaks the promises of both
those traits that their methods return a valid RawFd.

r? @aturon
cc @Mic92 @kamalmarhubi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants