Skip to content

Commit e086897

Browse files
committed
Add windows::CommandExt::raw_arg on Rust 1.62+
1 parent f76d325 commit e086897

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ fn main() {
1010
}
1111
};
1212

13+
if !cfg.probe_rustc_version(1, 62) {
14+
autocfg::emit("async_process_no_windows_raw_arg");
15+
}
1316
if !cfg.probe_rustc_version(1, 63) {
1417
autocfg::emit("async_process_no_io_safety");
1518
}

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,15 @@ impl AsRawFd for ChildStdin {
520520
}
521521
}
522522

523+
/// **Note:** This implementation is only available on Rust 1.63+.
523524
#[cfg(all(not(async_process_no_io_safety), unix))]
524525
impl AsFd for ChildStdin {
525526
fn as_fd(&self) -> BorrowedFd<'_> {
526527
self.0.as_fd()
527528
}
528529
}
529530

531+
/// **Note:** This implementation is only available on Rust 1.63+.
530532
#[cfg(all(not(async_process_no_io_safety), unix))]
531533
impl TryFrom<ChildStdin> for OwnedFd {
532534
type Error = io::Error;
@@ -604,13 +606,15 @@ impl AsRawFd for ChildStdout {
604606
}
605607
}
606608

609+
/// **Note:** This implementation is only available on Rust 1.63+.
607610
#[cfg(all(not(async_process_no_io_safety), unix))]
608611
impl AsFd for ChildStdout {
609612
fn as_fd(&self) -> BorrowedFd<'_> {
610613
self.0.as_fd()
611614
}
612615
}
613616

617+
/// **Note:** This implementation is only available on Rust 1.63+.
614618
#[cfg(all(not(async_process_no_io_safety), unix))]
615619
impl TryFrom<ChildStdout> for OwnedFd {
616620
type Error = io::Error;
@@ -677,13 +681,15 @@ impl AsRawFd for ChildStderr {
677681
}
678682
}
679683

684+
/// **Note:** This implementation is only available on Rust 1.63+.
680685
#[cfg(all(not(async_process_no_io_safety), unix))]
681686
impl AsFd for ChildStderr {
682687
fn as_fd(&self) -> BorrowedFd<'_> {
683688
self.0.as_fd()
684689
}
685690
}
686691

692+
/// **Note:** This implementation is only available on Rust 1.63+.
687693
#[cfg(all(not(async_process_no_io_safety), unix))]
688694
impl TryFrom<ChildStderr> for OwnedFd {
689695
type Error = io::Error;

src/windows.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Windows-specific extensions.
22
3+
#[cfg(not(async_process_no_windows_raw_arg))]
4+
use std::ffi::OsStr;
35
use std::os::windows::io::{AsRawHandle, RawHandle};
46
use std::os::windows::process::CommandExt as _;
57

@@ -16,6 +18,15 @@ pub trait CommandExt: crate::sealed::Sealed {
1618
///
1719
/// [1]: https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
1820
fn creation_flags(&mut self, flags: u32) -> &mut Command;
21+
22+
/// Append literal text to the command line without any quoting or escaping.
23+
///
24+
/// This is useful for passing arguments to `cmd.exe /c`, which doesn't follow
25+
/// `CommandLineToArgvW` escaping rules.
26+
///
27+
/// **Note:** This method is only available on Rust 1.62+.
28+
#[cfg(not(async_process_no_windows_raw_arg))]
29+
fn raw_arg<S: AsRef<OsStr>>(&mut self, text_to_append_as_is: S) -> &mut Command;
1930
}
2031

2132
impl crate::sealed::Sealed for Command {}
@@ -24,6 +35,12 @@ impl CommandExt for Command {
2435
self.inner.creation_flags(flags);
2536
self
2637
}
38+
39+
#[cfg(not(async_process_no_windows_raw_arg))]
40+
fn raw_arg<S: AsRef<OsStr>>(&mut self, text_to_append_as_is: S) -> &mut Command {
41+
self.inner.raw_arg(text_to_append_as_is);
42+
self
43+
}
2744
}
2845

2946
impl AsRawHandle for Child {

0 commit comments

Comments
 (0)