#[non_exhaustive]pub enum TokenCounterResolution {
Matched(Arc<dyn TokenCounter>),
Fallback(Arc<dyn TokenCounter>),
}Expand description
Outcome of TokenCounterRegistry::resolve — surfaces whether a
registered entry actually matched (provider, model) or the
registry’s fallback counter was returned because no entry matched.
Making fallback visible at the type level lets production cost
estimation paths log / alert on unknown models without inspecting
encoding_name() after the fact (invariant 15 — silent fallback is
not an option). Callers consume the resolution via pattern match —
there is no “give me the counter regardless” shortcut, because
such a shortcut would re-enable silent absorption of the fallback.
let counter = match registry.resolve("openai", "gpt-9") {
Resolution::Matched(c) => c,
Resolution::Fallback(c) => {
tracing::warn!("unknown model — using fallback counter");
c
}
};Operators that intentionally accept the fallback bind both arms to
the same name (Resolution::Matched(c) | Resolution::Fallback(c) => c).
The pattern is short, and the call site signals the deliberate
choice in source.
§Future variants
Resolution is #[non_exhaustive]. The two predicates
Self::is_match and Self::is_fallback each return true
only for their own variant — !is_match() and is_fallback()
are not equivalent under future variant additions. Operators
that want to alert on the no-match branch should match on
Self::Fallback explicitly.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Matched(Arc<dyn TokenCounter>)
A registered (provider, model_prefix) entry matched.
Fallback(Arc<dyn TokenCounter>)
No entry matched; the registry’s fallback counter is returned.
Implementations§
Source§impl Resolution
impl Resolution
Sourcepub fn counter(&self) -> &Arc<dyn TokenCounter> ⓘ
pub fn counter(&self) -> &Arc<dyn TokenCounter> ⓘ
Borrow the resolved counter regardless of which branch matched.
Operators that need the owned Arc consume the enum through a
pattern match.
Sourcepub const fn is_fallback(&self) -> bool
pub const fn is_fallback(&self) -> bool
true when no entry matched and the fallback was returned.
Distinct from !is_match() — Resolution is non_exhaustive,
so a future variant could make both predicates return false.
Trait Implementations§
Source§impl Clone for Resolution
impl Clone for Resolution
Source§fn clone(&self) -> Resolution
fn clone(&self) -> Resolution
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Resolution
impl !RefUnwindSafe for Resolution
impl Send for Resolution
impl Sync for Resolution
impl Unpin for Resolution
impl UnsafeUnpin for Resolution
impl !UnwindSafe for Resolution
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,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request