Skip to main content

Priority

Enum Priority 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Priority

Source§

fn clone(&self) -> Priority

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 Copy for Priority

Source§

impl Debug for Priority

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Priority

Source§

impl PartialEq for Priority

Source§

fn eq(&self, other: &Priority) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Priority

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more