pub struct SelectionContext {
pub estimated_cost: Option<f64>,
pub hash_key: Option<u64>,
pub tags: Option<HashMap<String, String>>,
pub exclude: Option<Vec<usize>>,
}Expand description
Context provided to strategies during node selection.
§Examples
use loadwise::SelectionContext;
// Empty context (most strategies work fine without it).
let ctx = SelectionContext::default();
// With a hash key for consistent hashing.
let ctx = SelectionContext::builder()
.hash_key(42)
.build();
// With estimated request cost and tags.
let ctx = SelectionContext::builder()
.estimated_cost(150.0)
.tags([("model".into(), "gpt-4".into())].into())
.build();
assert_eq!(ctx.tag("model"), Some("gpt-4"));
// Exclude specific indices (e.g., retry after failure).
let ctx = SelectionContext::builder()
.exclude(vec![0, 2])
.build();
assert!(ctx.is_excluded(0));
assert!(!ctx.is_excluded(1));Fields§
§estimated_cost: Option<f64>Estimated cost/weight of this request (e.g., token count).
hash_key: Option<u64>Hash key for consistent hashing strategies.
Arbitrary tags for routing decisions. None by default to avoid allocation.
exclude: Option<Vec<usize>>Indices to skip during selection (for retry scenarios).
None by default to avoid allocation.
Implementations§
Source§impl SelectionContext
impl SelectionContext
Sourcepub fn builder() -> SelectionContextBuilder
pub fn builder() -> SelectionContextBuilder
Create an instance of SelectionContext using the builder syntax
Source§impl SelectionContext
impl SelectionContext
Sourcepub fn is_excluded(&self, idx: usize) -> bool
pub fn is_excluded(&self, idx: usize) -> bool
Returns true if the given index should be skipped.
Uses linear search — O(n) in the size of the exclude list. Fine for typical retry scenarios (1–3 entries); for larger lists consider pre-filtering candidates instead.
Trait Implementations§
Source§impl Clone for SelectionContext
impl Clone for SelectionContext
Source§fn clone(&self) -> SelectionContext
fn clone(&self) -> SelectionContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SelectionContext
impl Debug for SelectionContext
Source§impl Default for SelectionContext
impl Default for SelectionContext
Source§fn default() -> SelectionContext
fn default() -> SelectionContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SelectionContext
impl RefUnwindSafe for SelectionContext
impl Send for SelectionContext
impl Sync for SelectionContext
impl Unpin for SelectionContext
impl UnsafeUnpin for SelectionContext
impl UnwindSafe for SelectionContext
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
Mutably borrows from an owned value. Read more