From f76d325959d2e06aa441455d56e0aa42dadb5181 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 30 Dec 2022 13:58:02 +0900 Subject: [PATCH] Seal CommandExt trait This is technically a breaking change, but we follow the standard library's decision that sealing CommandExt is fine. https://github.com/rust-lang/rust/commit/bfd1ccfb271f03aa85488408c3b03a15ad8d7c7f --- src/lib.rs | 4 ++++ src/unix.rs | 6 +++++- src/windows.rs | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e7b3b51..ae56332 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(); 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..96f9970 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -6,7 +6,10 @@ 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`. @@ -15,6 +18,7 @@ pub trait CommandExt { fn creation_flags(&mut self, flags: u32) -> &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);