diff --git a/build.rs b/build.rs index d5d1af7..6752846 100644 --- a/build.rs +++ b/build.rs @@ -10,6 +10,9 @@ fn main() { } }; + if !cfg.probe_rustc_version(1, 62) { + autocfg::emit("async_process_no_windows_raw_arg"); + } if !cfg.probe_rustc_version(1, 63) { autocfg::emit("async_process_no_io_safety"); } diff --git a/src/lib.rs b/src/lib.rs index ae56332..9f2bb6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -520,6 +520,7 @@ impl AsRawFd for ChildStdin { } } +/// **Note:** This implementation is only available on Rust 1.63+. #[cfg(all(not(async_process_no_io_safety), unix))] impl AsFd for ChildStdin { fn as_fd(&self) -> BorrowedFd<'_> { @@ -527,6 +528,7 @@ impl AsFd for ChildStdin { } } +/// **Note:** This implementation is only available on Rust 1.63+. #[cfg(all(not(async_process_no_io_safety), unix))] impl TryFrom for OwnedFd { type Error = io::Error; @@ -604,6 +606,7 @@ impl AsRawFd for ChildStdout { } } +/// **Note:** This implementation is only available on Rust 1.63+. #[cfg(all(not(async_process_no_io_safety), unix))] impl AsFd for ChildStdout { fn as_fd(&self) -> BorrowedFd<'_> { @@ -611,6 +614,7 @@ impl AsFd for ChildStdout { } } +/// **Note:** This implementation is only available on Rust 1.63+. #[cfg(all(not(async_process_no_io_safety), unix))] impl TryFrom for OwnedFd { type Error = io::Error; @@ -677,6 +681,7 @@ impl AsRawFd for ChildStderr { } } +/// **Note:** This implementation is only available on Rust 1.63+. #[cfg(all(not(async_process_no_io_safety), unix))] impl AsFd for ChildStderr { fn as_fd(&self) -> BorrowedFd<'_> { @@ -684,6 +689,7 @@ impl AsFd for ChildStderr { } } +/// **Note:** This implementation is only available on Rust 1.63+. #[cfg(all(not(async_process_no_io_safety), unix))] impl TryFrom for OwnedFd { type Error = io::Error; diff --git a/src/windows.rs b/src/windows.rs index 96f9970..453d3a5 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,5 +1,7 @@ //! Windows-specific extensions. +#[cfg(not(async_process_no_windows_raw_arg))] +use std::ffi::OsStr; use std::os::windows::io::{AsRawHandle, RawHandle}; use std::os::windows::process::CommandExt as _; @@ -16,6 +18,15 @@ pub trait CommandExt: crate::sealed::Sealed { /// /// [1]: https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags fn creation_flags(&mut self, flags: u32) -> &mut Command; + + /// Append literal text to the command line without any quoting or escaping. + /// + /// This is useful for passing arguments to `cmd.exe /c`, which doesn't follow + /// `CommandLineToArgvW` escaping rules. + /// + /// **Note:** This method is only available on Rust 1.62+. + #[cfg(not(async_process_no_windows_raw_arg))] + fn raw_arg>(&mut self, text_to_append_as_is: S) -> &mut Command; } impl crate::sealed::Sealed for Command {} @@ -24,6 +35,12 @@ impl CommandExt for Command { self.inner.creation_flags(flags); self } + + #[cfg(not(async_process_no_windows_raw_arg))] + fn raw_arg>(&mut self, text_to_append_as_is: S) -> &mut Command { + self.inner.raw_arg(text_to_append_as_is); + self + } } impl AsRawHandle for Child {