Skip to main content

TierBudgetSpec

Enum TierBudgetSpec 

Source
#[non_exhaustive]
pub enum TierBudgetSpec { Auto, Percent(u8), Bytes(u64), }
Expand description

One tiering budget, as configured (not yet resolved to bytes).

use kevy_config::TierBudgetSpec;

let spec = TierBudgetSpec::parse("50%")?;
assert_eq!(spec.resolve_with(Some(8_000_000_000)), Some(4_000_000_000));
assert_eq!(spec.resolve_with(None), None, "no bound detected: no guess");

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

Auto

"auto" — 0.70 × the detected memory bound, re-probed on the shard tick.

use kevy_config::TierBudgetSpec;

assert_eq!(TierBudgetSpec::parse("auto")?, TierBudgetSpec::Auto);
assert_eq!(TierBudgetSpec::Auto.resolve_with(Some(1000)), Some(700));
§

Percent(u8)

"70%" — that percent of the detected bound (1..=100).

use kevy_config::TierBudgetSpec;

assert_eq!(TierBudgetSpec::parse("25%")?, TierBudgetSpec::Percent(25));
assert_eq!(TierBudgetSpec::Percent(25).resolve_with(Some(4000)), Some(1000));
§

Bytes(u64)

"4gb" / plain integer — absolute bytes.

use kevy_config::TierBudgetSpec;

assert_eq!(TierBudgetSpec::parse("4gb")?, TierBudgetSpec::Bytes(4 << 30));
assert_eq!(TierBudgetSpec::Bytes(4096).resolve_with(None), Some(4096)); // needs no probe

Implementations§

Source§

impl TierBudgetSpec

Source

pub fn parse(s: &str) -> Result<TierBudgetSpec, ValueError>

Parse the wire/TOML/env text form. Accepts auto, N% (1..=100), and any parse_size literal (4gb, 512mb, bare bytes). Garbage errors by name.

use kevy_config::TierBudgetSpec;
assert_eq!(TierBudgetSpec::parse("70%"), Ok(TierBudgetSpec::Percent(70)));
assert!(TierBudgetSpec::parse("0%").is_err());
Source

pub fn resolve_with(self, detected_bound: Option<u64>) -> Option<u64>

Resolve to bytes given the probed memory bound. Bytes ignores the probe; Auto/Percent return None when no bound was detected (the caller refuses by name — never a silent guess).

use kevy_config::TierBudgetSpec;

let bound = Some(10 << 30); // e.g. a 10 GiB cgroup limit
assert_eq!(TierBudgetSpec::Auto.resolve_with(bound), Some((10 << 30) / 100 * 70));
assert_eq!(TierBudgetSpec::Percent(70).resolve_with(None), None);
assert_eq!(TierBudgetSpec::Bytes(1 << 20).resolve_with(bound), Some(1 << 20));
Source

pub fn to_config_string(self) -> String

The canonical config-file text form (auto / 70% / bytes).

use kevy_config::TierBudgetSpec;
assert_eq!(TierBudgetSpec::Percent(70).to_config_string(), "70%");
assert_eq!(TierBudgetSpec::Bytes(4096).to_config_string(), "4096");

Trait Implementations§

Source§

impl Clone for TierBudgetSpec

Source§

fn clone(&self) -> TierBudgetSpec

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 TierBudgetSpec

Source§

impl Debug for TierBudgetSpec

Source§

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

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

impl Eq for TierBudgetSpec

Source§

impl Hash for TierBudgetSpec

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TierBudgetSpec

Source§

fn eq(&self, other: &TierBudgetSpec) -> 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 TierBudgetSpec

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