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
impl RateLimitUnit
Source§impl RateLimitUnit
impl RateLimitUnit
Sourcepub const ALL: &'static [Self]
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.
Sourcepub const fn as_suffix(self) -> &'static str
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.
Sourcepub const fn window(self) -> Duration
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.
Sourcepub fn from_suffix(suffix: &str) -> Option<Self>
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.
Sourcepub fn from_window(window: Duration) -> Option<Self>
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.
Sourcepub fn window_from_suffix(suffix: &str) -> Option<Duration>
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
impl Clone for RateLimitUnit
Source§fn clone(&self) -> RateLimitUnit
fn clone(&self) -> RateLimitUnit
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RateLimitUnit
Source§impl Debug for RateLimitUnit
impl Debug for RateLimitUnit
Source§impl<'de> Deserialize<'de> for RateLimitUnit
impl<'de> Deserialize<'de> for RateLimitUnit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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.
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.
impl Eq for RateLimitUnit
Source§impl Hash for RateLimitUnit
impl Hash for RateLimitUnit
Source§impl PartialEq for RateLimitUnit
impl PartialEq for RateLimitUnit
Source§impl Serialize for RateLimitUnit
impl Serialize for RateLimitUnit
impl StructuralPartialEq for RateLimitUnit
Auto Trait Implementations§
impl Freeze for RateLimitUnit
impl RefUnwindSafe for RateLimitUnit
impl Send for RateLimitUnit
impl Sync for RateLimitUnit
impl Unpin for RateLimitUnit
impl UnsafeUnpin for RateLimitUnit
impl UnwindSafe for RateLimitUnit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.