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 e7b3b51..9f2bb6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,6 +82,10 @@ pub mod unix; #[cfg(windows)] pub mod windows; +mod sealed { + pub trait Sealed {} +} + /// An event delivered every time the SIGCHLD signal occurs. static SIGCHLD: Event = Event::new(); @@ -516,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<'_> { @@ -523,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; @@ -600,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<'_> { @@ -607,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; @@ -673,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<'_> { @@ -680,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/unix.rs b/src/unix.rs index 4208ecf..034f881 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -7,7 +7,10 @@ use std::os::unix::process::CommandExt as _; use crate::Command; /// Unix-specific extensions to the [`Command`] builder. -pub trait CommandExt { +/// +/// This trait is sealed: it cannot be implemented outside `async-process`. +/// This is so that future additional methods are not breaking changes. +pub trait CommandExt: crate::sealed::Sealed { /// Sets the child process's user ID. This translates to a /// `setuid` call in the child process. Failure in the `setuid` /// call will cause the spawn to fail. @@ -88,6 +91,7 @@ pub trait CommandExt { S: AsRef; } +impl crate::sealed::Sealed for Command {} impl CommandExt for Command { fn uid(&mut self, id: u32) -> &mut Command { self.inner.uid(id); diff --git a/src/windows.rs b/src/windows.rs index 64c042c..453d3a5 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,25 +1,46 @@ //! 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 _; use crate::{Child, Command}; /// Windows-specific extensions to the [`Command`] builder. -pub trait CommandExt { +/// +/// This trait is sealed: it cannot be implemented outside `async-process`. +/// This is so that future additional methods are not breaking changes. +pub trait CommandExt: crate::sealed::Sealed { /// Sets the [process creation flags][1] to be passed to `CreateProcess`. /// /// These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`. /// /// [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 {} impl CommandExt for Command { fn creation_flags(&mut self, flags: u32) -> &mut 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 {