Skip to content

Commit 8e3abf9

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 8e3abf9

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ categories = ["asynchronous", "network-programming", "os"]
1515
exclude = ["/.*"]
1616

1717
[lints.rust]
18-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(polling_test_poll_backend)'] }
18+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(polling_test_poll_backend)', 'cfg(async_io_no_pipe)' ] }
1919

2020
[[bench]]
2121
name = "io"
@@ -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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// We use "no_*" instead of "has_*" here. For (non-Cargo) build processes
11+
// that don't run build.rs, the negated version gives us a recent
12+
// feature-set by default.
13+
if !cfg.probe_rustc_version(1, 87) {
14+
autocfg::emit("async_io_no_pipe");
15+
}
16+
}

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)