Skip to main content

RoutingEngine

Struct RoutingEngine 

Source
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

Source

pub fn new() -> Self

Construct an empty engine. Use RoutingEngine::with_routes for the common case of building from a stored config.

Source

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.

Source

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.

Source

pub fn routes(&self) -> &[Route]

All routes, descending priority order.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> RoutingEngine

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 Debug for RoutingEngine

Source§

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

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

impl Default for RoutingEngine

Source§

fn default() -> RoutingEngine

Returns the “default value” for a type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more