-
Notifications
You must be signed in to change notification settings - Fork 63
Implement From<RawFd> for Stdio #50
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
base: master
Are you sure you want to change the base?
Conversation
polarathene
left a comment
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.
I'm aware that there's not much point applying this feedback here given the project doesn't appear to be actively maintained. Thought I'd chime in with the feedback anyway 👍
| impl From<RawFd> for Stdio { | ||
| fn from(fd: RawFd) -> Self { | ||
| Self { | ||
| inner: StdioImpl::RedirectToRawFd(fd), | ||
| } | ||
| } | ||
| } |
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.
You may want to look at preferring the safe equivalents that are available now? sunfishcode/io-lifetimes#38
If a type implements
AsRawFd,FromRawFd, and/orIntoRawFd, it usually wantsAsFd,From<OwnedFd>, and/orFrom<T> for OwnedFd, respectively.
Since Rust 1.63.0 (Aug 2022), OwnedFd became available, which provides as_fd() and as_raw_fd() if you need to get BorrowedFd or RawFd types (original RFC for further context).
| impl From<RawFd> for Stdio { | |
| fn from(fd: RawFd) -> Self { | |
| Self { | |
| inner: StdioImpl::RedirectToRawFd(fd), | |
| } | |
| } | |
| } | |
| impl From<OwnedFd> for Stdio { | |
| fn from(fd: OwnedFd) -> Self { | |
| Self { | |
| inner: StdioImpl::RedirectToFd(fd), | |
| } | |
| } | |
| } |
- You would also need to change the import from
use std::os::unix::io::RawFd;touse std::os::fd::OwnedFd; - There's also a
AsRawFdimport and aas_raw_fd()call for theRedirectToFileenum variant, that can get anOwnedFdsince1.63.0in a similar way.
That said, I'm not quite sure why Stdio struct exists here instead of using the std::process::Stdio one? It already supports From for file and fd, while there is a separate function call null() for getting the equivalent /dev/null and the Keep enum variant seems to be for a No-op.
Ah.. so this is for redirection of the streams handled in the redirect_standard_streams() call further down. So at the time Rust didn't have an equivalent built-in for Stdio but it does now since Rust 1.74 (Nov 2023). So if raising the MSRV were viable, one could switch to that to simplify 😎
|
Thanks for the feedback! Unfortunately, I no longer have a use case for this feature and this PR is 2 years old, so I doubt it will be merged. Anyway, if someone decides to fork the project and find this feature useful, I'd be happy to contribute. |
Raised in this comment: knsd/daemonize#50 (comment)
Fixes #49