Skip to main content

RateLimitUnit

Enum RateLimitUnit 

Source
pub enum RateLimitUnit {
    Second,
    Minute,
    Hour,
}
Expand description

Typed closed-set enum for the three canonical :politicas :rate-limit :window units — Second / Minute / Hour — the rate_limit_codec round-trips losslessly ("<n>/s" / "<n>/m" / "<n>/h").

The {"s" ↔ 1s, "m" ↔ 60s, "h" ↔ 3600s} bijection every consumer of the :politicas :rate-limit unit surface reads from ([rate_limit_codec::parse]’s unit → Duration dispatch, [rate_limit_codec::render]’s Duration → unit projection, the [is_canonical_rate_limit_window] predicate the AplicacaoSpec::validate_politicas gate keys off, the future M4 per-Aplicacao Envoy config reconciler’s local_rate_limit.token_bucket.fill_interval projection) now lives inside this typed enum’s match self arms — a future rate-limit-unit addition (a "d" day suffix once Envoy’s rate_limit_action grows daily-bucket support) is one new variant plus the exhaustiveness arms on the four methods, so every consumer picks it up by compile-time construction rather than a runtime table-scan miss.

The prior RATE_LIMIT_UNIT_TABLE: &[(&str, u64)] slice-of-tuples was scanned via find_map at every projection call — an untyped runtime walk that carried no compile-time link between the parse arm’s accepted suffixes, the render arm’s emitted suffixes, and the validate gate’s accepted windows. A future rate-limit-unit addition that landed one row without threading through the other consumers (or a copy-paste flip that collapsed two rows onto one suffix) would silently split the accepted-set across the three consumers — the parse arm accepts "d" and rejects "s", the render arm emits "h" for a 24h window that parse can’t round-trip, the validate gate misses one canonical window. Lifting the pairs onto a typed closed-set enum with exhaustive match arms makes any such half-landed extension a caixa-core build error (the compiler enforces arm coverage on every method), not a silent per-consumer drift surfacing at apply time. Same “closed-set typed-enum discriminator” discipline the sibling PlacementStrategy (cc8f749), crate::supervisor::RestartStrategy, crate::supervisor::RestartPolicy, crate::upgrade::UpgradeInstruction, and crate::CaixaKind closed-set typed enums carry on their respective closed-set axes — extended onto the seventh closed-set typed-enum discriminator axis on the caixa typed surface (the :politicas :rate-limit :window canonical-unit axis).

Variants§

§

Second

1-second window — canonical author-surface suffix "s" ("<n>/s"), maps onto Envoy’s local_rate_limit.token_bucket.fill_interval with a 1s magnitude.

§

Minute

1-minute window — canonical author-surface suffix "m" ("<n>/m"), maps onto Envoy’s local_rate_limit.token_bucket.fill_interval with a 60s magnitude.

§

Hour

1-hour window — canonical author-surface suffix "h" ("<n>/h"), maps onto Envoy’s local_rate_limit.token_bucket.fill_interval with a 3600s magnitude.

Implementations§

Source§

impl RateLimitUnit

Source

pub const fn is_second(&self) -> bool

Source

pub const fn is_minute(&self) -> bool

Source

pub const fn is_hour(&self) -> bool

Source§

impl RateLimitUnit

Source

pub const ALL: &'static [Self]

Exhaustive iteration surface for every consumer that reads the full canonical-unit set (the byte-parity witness against the prior RATE_LIMIT_UNIT_TABLE shape, the future M4 admission webhook’s accepted-suffix listing in its rejection body, any future round-trip fuzz harness). A future variant addition to RateLimitUnit extends this slice as a single edit and every consumer picks up the new entry by construction — the compiler- checked exhaustiveness on the sibling method match arms is the build-time guarantee that no arm forgets to grow.

Source

pub const fn as_suffix(self) -> &'static str

Canonical author-surface suffix — the "s" / "m" / "h" byte- string every <n>/<unit> rate-limit shape carries after its / separator. The single source of truth the codec’s parse and render arms both dispatch on: the parse arm matches an incoming suffix against every RateLimitUnit::ALL entry’s as_suffix output; the render arm emits the entry’s as_suffix verbatim after the rate magnitude.

Source

pub const fn window(self) -> Duration

Canonical Duration for this unit — the token-bucket refill period the RateLimit::window axis carries when the surrounding slot’s :rate-limit author surface named this unit.

Source

pub fn from_suffix(suffix: &str) -> Option<Self>

Parse the <n>/<unit>-shaped suffix into the typed enum, or None when suffix is outside the closed-set arm-string set Self::as_suffix emits. The single str → Self projection [rate_limit_codec::parse] consumes.

Source

pub fn from_window(window: Duration) -> Option<Self>

Recognize a canonical rate-limit Duration as one of the three arms, or None when window carries sub-second residue or a second-magnitude outside the closed-set arm-window set Self::window emits. The single Duration → Self projection [rate_limit_codec::render] + [is_canonical_rate_limit_window] both consume.

Source

pub fn window_from_suffix(suffix: &str) -> Option<Duration>

Canonical rate-limit Duration for a unit suffix, or None when suffix is outside the closed-set arm-string set Self::as_suffix emits. Composes Self::from_suffix with Self::window — the single &str → Duration projection [rate_limit_codec::parse] consumes.

The peer Duration → &'static str axis folded onto the substrate primitive RateLimit::canonical_unit typed accessor once both production consumers ([rate_limit_codec::render] and AplicacaoSpec::validate_politicas’s canonical-window gate) migrated (61421a6): the free helper’s Duration → &str projection is now the two-step composition rl.canonical_unit().map(RateLimitUnit::as_suffix) every consumer reads through the typed accessor. This lift closes the peer &str → Duration axis by folding the vestigial module-private rate_limit_window_from_unit delegate onto this associated method — the codec’s parse arm and every future wire-side consumer of the &str → Duration projection (a future admission-webhook that reads a :rate-limit shape off a CR spec’s raw string value before it’s promoted to a validated typed slot, a future feira lint shape-probe that reads the author-surface bytes verbatim) now reach for exactly one typed dispatch on the substrate primitive.

Same “closed-set typed-enum discriminator with canonical projections per axis” discipline the sibling Self::as_suffix / Self::window / Self::from_suffix / Self::from_window methods carry — this associated method closes the fifth (and last unlifted) projection axis on the arm-table, so the closed-set enum now owns every str ↔ Duration ↔ Self typed dispatch every consumer of the :politicas :rate-limit :window axis reaches through. A future rate-limit-unit addition (a "d" day suffix once Envoy’s rate_limit_action grows daily-bucket support, a "ms" sub-second window once high-throughput per-edge policies come into scope per MESH-COMPOSITION §III.2 #3) is one new variant plus one arm per method — the compiler enforces exhaustiveness on every consumer’s match self arms and picks the new unit up by construction across all five projections.

Trait Implementations§

Source§

impl Clone for RateLimitUnit

Source§

fn clone(&self) -> RateLimitUnit

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 RateLimitUnit

Source§

impl Debug for RateLimitUnit

Source§

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

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

impl<'de> Deserialize<'de> for RateLimitUnit

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for RateLimitUnit

Route std::fmt::Display through RateLimitUnit::as_suffix, so every consumer that formats a canonical rate-limit unit as user- facing text (future M4 admission-webhook rejection bodies naming the accepted-suffix set, future feira app graph per-:politicas unit column) lands on the same "s" / "m" / "h" byte-string the codec’s parse arm accepts and the render arm emits. Same as_str-through-Display convergence discipline the sibling PlacementStrategy, crate::CaixaKind, crate::supervisor::RestartStrategy, and crate::supervisor::RestartPolicy closed-set typed enums carry.

Source§

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

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

impl Eq for RateLimitUnit

Source§

impl Hash for RateLimitUnit

Source§

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

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 RateLimitUnit

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for RateLimitUnit

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RateLimitUnit

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.