Skip to content

Commit 9379235

Browse files
committed
impl IoSafe for std::io::PipeReader & std::io::PipeWriter
It would be handy to have async wrappers for the pipe types (from std::io::pipe()), so impl IoSafe for both. The pipe types were introduced in 1.87, but the MSRV for async-io appears to be 1.63 currently. So, protect the impls with cfg()s and use autocfg to detect the type availbility, similar to what was done in a20076f ("Implement I/O-safe traits (smol-rs#84)") Signed-off-by: Jeremy Kerr <[email protected]>
1 parent 25298e7 commit 9379235

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ tracing = { version = "0.1.37", default-features = false, optional = true }
4040
[target.'cfg(windows)'.dependencies]
4141
windows-sys = { version = "0.60.0", features = ["Win32_Foundation"] }
4242

43+
[build-dependencies]
44+
autocfg = "1"
45+
4346
[dev-dependencies]
4447
async-channel = "2.0.0"
4548
async-net = "2.0.0"

build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fn main() {
2+
let cfg = match autocfg::AutoCfg::new() {
3+
Ok(cfg) => cfg,
4+
Err(e) => {
5+
println!("cargo:warning=async-io: failed to detect compiler features: {e}");
6+
return;
7+
}
8+
};
9+
10+
// emit expected config settings; may be replaced with
11+
// autocfg::emit_possibility if we update to autocfg>=1.5
12+
println!("cargo:rustc-check-cfg=cfg(async_io_no_pipe)");
13+
14+
// We use "no_*" instead of "has_*" here. For (non-Cargo) build processes
15+
// that don't run build.rs, the negated version gives us a recent
16+
// feature-set by default.
17+
if !cfg.probe_rustc_version(1, 87) {
18+
autocfg::emit("async_io_no_pipe");
19+
}
20+
}

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,13 @@ unsafe impl IoSafe for std::process::ChildStderr {}
12521252
#[cfg(unix)]
12531253
unsafe impl IoSafe for std::os::unix::net::UnixStream {}
12541254

1255+
// PipeReader & PipeWriter require std >= 1.87, our MSRV is 1.63, hence
1256+
// conditional on cfg()s, generated from build.rs
1257+
#[cfg(not(async_io_no_pipe))]
1258+
unsafe impl IoSafe for std::io::PipeReader {}
1259+
#[cfg(not(async_io_no_pipe))]
1260+
unsafe impl IoSafe for std::io::PipeWriter {}
1261+
12551262
unsafe impl<T: IoSafe + Read> IoSafe for std::io::BufReader<T> {}
12561263
unsafe impl<T: IoSafe + Write> IoSafe for std::io::BufWriter<T> {}
12571264
unsafe impl<T: IoSafe + Write> IoSafe for std::io::LineWriter<T> {}

0 commit comments

Comments
 (0)