pub struct SpawnSpec { /* private fields */ }Expand description
Typed spawn description accepted by the blessed process boundary.
Implementations§
Source§impl SpawnSpec
impl SpawnSpec
Sourcepub fn new(program: impl Into<OsString>) -> Self
pub fn new(program: impl Into<OsString>) -> Self
Create a direct (non-shell) command description.
Sourcepub fn from_std_command(command: Command) -> Self
pub fn from_std_command(command: Command) -> Self
Spawn a caller-built std::process::Command verbatim.
The command keeps everything the declarative builder cannot carry:
env_remove scrubs of inherited variables, env_clear, non-Unicode
argv, its working directory and any hooks the caller installed. The
spec still governs stdio routing (its stream modes replace whatever
the command had), process group, niceness, creation flags, the
address-space limit, owner-death containment and spawn admission.
Those options are applied with the same launch mapping NativeProcess
uses (configure_process_command), not the declarative one, so a
command is configured exactly once. Adding arguments, environment,
env_clear or a working directory to an override spec is rejected at
spawn, because it would be silently ignored. Owner-death containment
of an override is refused on Windows until the per-spawn Job Object is
expressible here.
The command is consumed by the first successful or failed spawn; a clone of this spec that spawns afterwards gets an error.
Sourcepub fn creation_flags(self, flags: Option<u32>) -> Self
pub fn creation_flags(self, flags: Option<u32>) -> Self
Set host creation flags (Windows CREATE_*; ignored elsewhere).
Only valid with Self::from_std_command; the declarative spawn
path rejects it rather than dropping it.
Sourcepub fn address_space_limit_bytes(self, limit: Option<u64>) -> Self
pub fn address_space_limit_bytes(self, limit: Option<u64>) -> Self
Cap the child’s address space (Linux RLIMIT_AS; the Windows cap is
enforced by the owner’s Job Object, not here).
Only valid with Self::from_std_command; the declarative spawn
path rejects it rather than dropping it.
Sourcepub fn arg(self, arg: impl Into<OsString>) -> Self
pub fn arg(self, arg: impl Into<OsString>) -> Self
Append one argument without requiring UTF-8.
Sourcepub fn current_dir(self, path: impl Into<PathBuf>) -> Self
pub fn current_dir(self, path: impl Into<PathBuf>) -> Self
Set the child working directory.
Sourcepub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self
pub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self
Add an environment override.
Sourcepub fn clear_env(self, clear: bool) -> Self
pub fn clear_env(self, clear: bool) -> Self
Start with an empty inherited environment before applying overrides.
Sourcepub fn stdin(self, mode: StreamMode) -> Self
pub fn stdin(self, mode: StreamMode) -> Self
Configure child stdin.
Sourcepub fn stdout(self, mode: StreamMode) -> Self
pub fn stdout(self, mode: StreamMode) -> Self
Configure child stdout.
Sourcepub fn stderr(self, mode: StreamMode) -> Self
pub fn stderr(self, mode: StreamMode) -> Self
Configure child stderr.
Sourcepub fn create_process_group(self, create: bool) -> Self
pub fn create_process_group(self, create: bool) -> Self
Put the child in its own process group.
This is what makes a group-wide soft signal addressable at all:
PlatformEmergencySignal::terminate_group_soft is a no-op without
it, because on POSIX the negative-PID signal would otherwise reach the
caller’s own group, and on Windows GenerateConsoleCtrlEvent only
routes to children spawned with CREATE_NEW_PROCESS_GROUP. It also
detaches the child from the parent’s console Ctrl+C, so it is opt-in.
Sourcepub fn kill_when_owner_dies(self, kill: bool) -> Self
pub fn kill_when_owner_dies(self, kill: bool) -> Self
Kill this child when the spawning process exits unexpectedly.
Linux uses PR_SET_PDEATHSIG(SIGTERM) plus a pre-exec hard-exit race
guard when the parent changed before that signal could be armed.
Windows assigns the child to a
process-wide kill-on-close Job Object. macOS forks a kqueue supervisor
before exec and reports spawn success only after its owner and child
watches are registered.
Sourcepub fn nice(self, nice: Option<i32>) -> Self
pub fn nice(self, nice: Option<i32>) -> Self
Apply the host’s existing niceness policy at child creation.
On Unix this is the requested setpriority(PRIO_PROCESS) niceness.
Windows maps the established niceness bands to process creation
priority classes; it is deliberately a coarse host mapping rather
than a claim that numeric nice values are portable.
Sourcepub fn priority(self, priority: ProcessPriority) -> Self
pub fn priority(self, priority: ProcessPriority) -> Self
Select portable scheduling intent at native process creation.
Sourcepub fn priority_best_effort(self, priority: ProcessPriority) -> Self
pub fn priority_best_effort(self, priority: ProcessPriority) -> Self
Request portable scheduling intent where host policy permits it.
The current host launch boundary applies this at creation; platforms that reject the requested class retain their native error behavior.
Sourcepub fn spawn_admission(self, admission: SpawnAdmission) -> Self
pub fn spawn_admission(self, admission: SpawnAdmission) -> Self
Acquire a caller-owned permit around the native spawn attempt.
Sourcepub async fn spawn(self) -> Result<PlatformChild>
pub async fn spawn(self) -> Result<PlatformChild>
Spawn using the canonical asynchronous platform operation.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SpawnSpec
impl !UnwindSafe for SpawnSpec
impl Freeze for SpawnSpec
impl Send for SpawnSpec
impl Sync for SpawnSpec
impl Unpin for SpawnSpec
impl UnsafeUnpin for SpawnSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more