Add windows::CommandExt::raw_arg on Rust 1.62+

This commit is contained in:
Taiki Endo 2022-12-30 14:23:57 +09:00
parent f76d325959
commit e086897e53
3 changed files with 26 additions and 0 deletions

View File

@ -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");
}

View File

@ -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<ChildStdin> 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<ChildStdout> 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<ChildStderr> for OwnedFd {
type Error = io::Error;

View File

@ -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<S: AsRef<OsStr>>(&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<S: AsRef<OsStr>>(&mut self, text_to_append_as_is: S) -> &mut Command {
self.inner.raw_arg(text_to_append_as_is);
self
}
}
impl AsRawHandle for Child {