pub trait RankingStrategy {
// Required methods
fn policy_name(&self) -> &str;
fn order(&self, frames: &[(String, ContextFrame)]) -> Vec<usize>;
}Expand description
A host’s policy for ordering frames drawn from more than one provider —
the choice SPEC.md §6.6 (F10) says a host owns and must name.
A strategy reports a permutation of the input indices, best first. It
ranks; it never filters. Dropping evidence is the budget packer’s job in
super::compose_for_prompt_with, which excludes a frame with a recorded
ExclusionReason so the audit still explains
every drop. A strategy that quietly returned fewer indices would put frames
into neither the prompt nor the audit.
§Contract
order(frames)returns each index in0..frames.len()exactly once.- The result depends only on
framesas a set — not on their arrival order, and not on anything that varies between two runs over the same input. AHashMapiteration is the usual way to get this wrong.
rank_with holds the first half rather than trusting it: an index out of
range or repeated is skipped, and any frame a strategy failed to place is
appended in canonical order, so a third-party strategy cannot make the
reference host lose evidence. It repairs rather than panicking — a library
that aborted a host’s turn over a ranking bug would be a worse failure than
the one it caught. is_ranking_permutation is the assertion to put in a
strategy’s own tests.
Required Methods§
Sourcefn policy_name(&self) -> &str
fn policy_name(&self) -> &str
The policy’s name, for a host that has to state which cross-provider ordering it applied. F10 requires a host to document the choice; a strategy that cannot say what it is makes that impossible, which is why this has no default implementation.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".