Skip to main content

SpawnSpec

Struct SpawnSpec 

Source
pub struct SpawnSpec { /* private fields */ }
Expand description

Typed spawn description accepted by the blessed process boundary.

Implementations§

Source§

impl SpawnSpec

Source

pub fn new(program: impl Into<OsString>) -> Self

Create a direct (non-shell) command description.

Source

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.

Source

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.

Source

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.

Source

pub fn arg(self, arg: impl Into<OsString>) -> Self

Append one argument without requiring UTF-8.

Source

pub fn current_dir(self, path: impl Into<PathBuf>) -> Self

Set the child working directory.

Source

pub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self

Add an environment override.

Source

pub fn clear_env(self, clear: bool) -> Self

Start with an empty inherited environment before applying overrides.

Source

pub fn stdin(self, mode: StreamMode) -> Self

Configure child stdin.

Source

pub fn stdout(self, mode: StreamMode) -> Self

Configure child stdout.

Source

pub fn stderr(self, mode: StreamMode) -> Self

Configure child stderr.

Source

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.

Source

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.

Source

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.

Source

pub fn priority(self, priority: ProcessPriority) -> Self

Select portable scheduling intent at native process creation.

Source

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.

Source

pub fn spawn_admission(self, admission: SpawnAdmission) -> Self

Acquire a caller-owned permit around the native spawn attempt.

Source

pub async fn spawn(self) -> Result<PlatformChild>

Spawn using the canonical asynchronous platform operation.

Trait Implementations§

Source§

impl Clone for SpawnSpec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpawnSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.