pub struct RoutingEngine { /* private fields */ }Expand description
Rule engine. Hold routes sorted by descending priority; iterate to find the first match.
Implementations§
Source§impl RoutingEngine
impl RoutingEngine
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty engine. Use RoutingEngine::with_routes for the
common case of building from a stored config.
Sourcepub fn with_routes(routes: impl IntoIterator<Item = Route>) -> Self
pub fn with_routes(routes: impl IntoIterator<Item = Route>) -> Self
Construct from a collection of routes. Internally sorted descending by priority — the order the caller passes them in does not matter.
Sourcepub fn add(&mut self, route: Route)
pub fn add(&mut self, route: Route)
Add a route in-place and re-sort. Hot-path callers should prefer
RoutingEngine::with_routes to amortize the sort.
Sourcepub fn evaluate(
&self,
req: &ChatCompletionRequest,
ctx: &RequestContext,
input_tokens_estimate: u32,
) -> Option<&Route>
pub fn evaluate( &self, req: &ChatCompletionRequest, ctx: &RequestContext, input_tokens_estimate: u32, ) -> Option<&Route>
Find the first matching route for (req, ctx). Returns None when no
enabled route matches — caller dispatches the request unchanged.
input_tokens_estimate is supplied by the caller — typically a cheap
length-over-4 heuristic, or the result of a tokenizer call cached at
the request boundary. The engine never tokenizes itself.
Sourcepub fn evaluate_with_cost(
&self,
req: &ChatCompletionRequest,
ctx: &RequestContext,
input_tokens_estimate: u32,
estimated_cost_usd: Option<f64>,
) -> Option<&Route>
pub fn evaluate_with_cost( &self, req: &ChatCompletionRequest, ctx: &RequestContext, input_tokens_estimate: u32, estimated_cost_usd: Option<f64>, ) -> Option<&Route>
Like RoutingEngine::evaluate but with a pre-flight cost estimate (USD)
for estimated_cost_gt / estimated_cost_lt conditions. None means the
cost is unknown (e.g. the requested model has no pricing) — cost
conditions then never match, mirroring the engine’s other “unknown data →
don’t match” stances.
Sourcepub fn find_by_name(&self, name: &str) -> Option<&Route>
pub fn find_by_name(&self, name: &str) -> Option<&Route>
Find an enabled route by exact name (case-sensitive), bypassing condition evaluation — used to honor a forced-route request header.
Trait Implementations§
Source§impl Clone for RoutingEngine
impl Clone for RoutingEngine
Source§fn clone(&self) -> RoutingEngine
fn clone(&self) -> RoutingEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more