uucore::pipes::pipe_with_size: return OwnedFd without conversion#12274
uucore::pipes::pipe_with_size: return OwnedFd without conversion#12274oech3 wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
| #[cfg(any(target_os = "linux", target_os = "android"))] | ||
| fn pipe_with_size(s: usize) -> std::io::Result<(File, File)> { | ||
| let (read, write) = rustix::pipe::pipe()?; | ||
| fn pipe_with_size(s: usize) -> std::io::Result<(OwnedFd, OwnedFd)> { |
There was a problem hiding this comment.
Why do we need to change the types from File to OwnedFd?
There was a problem hiding this comment.
We can deffer conversion until when it is needed (which is cold code path at most cases). Also it is natural to just use rustix provided one.
There was a problem hiding this comment.
The conversion is zero-cost, see https://rust.godbolt.org/z/6sqafnM5Y
There was a problem hiding this comment.
But it is not clear from code and much simpler.
There was a problem hiding this comment.
I don't want to write many (*,*)s. But OK to close this.
There was a problem hiding this comment.
This is low-priority, but it might useful if rustc reject trying to seeking (and other operations impossible) pipe as File at compile time.
OwnedFd satisfies it.
There was a problem hiding this comment.
The Seek trait does not promise that the object is actually seekable; std::io::Seek:seek returns a std::io::Result, see rust-lang/rust#72802.
RawReaderreusable