#[non_exhaustive]pub enum Priority {
Idle,
BelowNormal,
Normal,
AboveNormal,
High,
}Expand description
A portable CPU-scheduling priority for a child process (see
Command::priority), mapped onto the native
primitive at spawn time: Unix setpriority/nice (applied through the
same pre_exec seam as uid/gid),
Windows priority class (OR’d into creation_flags, the same seam as
create_no_window).
Unlike the privilege builders, every variant here is supported on both
platform families — setpriority is plain POSIX (Linux, macOS, the BSDs
alike) and every Windows edition has all five priority classes — so
Command::priority never yields
ErrorReason::Unsupported.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Idle
Lowest scheduling priority — runs only when the system is otherwise
idle. Unix: nice(19). Windows: IDLE_PRIORITY_CLASS.
BelowNormal
Below the default priority — polite background work that still makes
steady progress. Unix: nice(10). Windows: BELOW_NORMAL_PRIORITY_CLASS.
Normal
The default OS priority. Unix: nice(0). Windows: NORMAL_PRIORITY_CLASS.
Unix caveat: this is a no-op only when the spawning process
itself has nice == 0. A child normally inherits its parent’s nice
value, so setting Normal explicitly under a positively-niced parent
(e.g. a process launched via nice(1) in a CI/batch scheduler) asks
the kernel to lower the child’s nice back to 0 — the same kind
of decrease as AboveNormal/High,
and subject to the same CAP_SYS_NICE/root requirement and
ErrorReason::Spawn failure mode described there.
Windows is unaffected: NORMAL_PRIORITY_CLASS never needs a privilege
check.
AboveNormal
Above the default priority. Unix: nice(-5). Windows:
ABOVE_NORMAL_PRIORITY_CLASS.
Unix caveat: same privilege requirement as
High — lowering nice below its inherited value
needs CAP_SYS_NICE/root, and without it the spawn fails as
ErrorReason::Spawn rather than silently applying a
smaller increase.
High
Highest ordinary (non-real-time) priority.
Unix caveat: lowering nice below its inherited value needs
CAP_SYS_NICE (Linux) or an equivalent privilege elsewhere; without it
the OS refuses the change and the spawn fails as
ErrorReason::Spawn, exactly like any other rejected
pre_exec hook — it is never silently downgraded to a lower priority.
Windows needs no special privilege for HIGH_PRIORITY_CLASS.
Unix: nice(-10). Windows: HIGH_PRIORITY_CLASS.
Implementations§
Source§impl Priority
impl Priority
Sourcepub fn name(&self) -> &'static str
pub fn name(&self) -> &'static str
This priority’s stable machine identifier: a short, lowercase
snake_case string ("idle", "below_normal", "normal",
"above_normal", "high") that is part of the crate’s compatibility
surface.
Use it for machine-readable output — a CLI’s JSONL schema, a
cross-language binding, a structured log field — where a consumer needs
one canonical spelling per variant instead of hand-maintaining its own
mapping table. It is a diagnostic name, not a wire/serialization
format, but it is held stable all the same: a new variant gets a
new identifier, and an existing identifier is never renamed
without a major release. from_name parses it back —
the direction a config file or CLI flag choosing a priority needs.
Sourcepub fn from_name(name: &str) -> Option<Self>
pub fn from_name(name: &str) -> Option<Self>
Parse a name identifier back into a Priority — the
direction a config value or CLI flag selecting a priority needs.
Returns None for any string that is not exactly one of the stable
identifiers — an honest miss, never a silent default, so an unknown
value fails loudly rather than defaulting to some priority the caller
never asked for. Round-trips with name:
Priority::from_name(p.name()) == Some(p) for every variant.