Skip to main content

AlternativeFilter

Trait AlternativeFilter 

Source
pub trait AlternativeFilter: Send + Sync {
    // Required methods
    fn filter(&self, alts: &[Candidate], ctx: &FilterContext<'_>) -> Vec<usize>;
    fn classification(&self) -> FilterClass;
    fn name(&self) -> &'static str;
}
Expand description

One filter in the optimizer ranker’s chain. Given the current candidate list + context, returns the indices of candidates to keep. The chain applies filters in order; each one sees the survivors of the previous.

§Implementor contract

  • Pure function of inputs. Don’t read globals or mutate external state — the filter is called at plan time, possibly from a compiler thread, and idempotency matters for plan-cache reuse.
  • Sorted, distinct, in-range indices. The returned Vec<usize> must be sorted strictly ascending, contain only indices < alts.len(), and have no duplicates. The chain pipeline calls crate::ranker::AlternativeSet::retain_indices which debug_assert!s these invariants.
  • Empty result = “I reject everything.” Soft filters that would over-restrict are skipped by the pipeline; hard filters are surfaced as Error::FilterRejected. Filters themselves don’t need to know which class they’re in — just return what they think is admissible.

Required Methods§

Source

fn filter(&self, alts: &[Candidate], ctx: &FilterContext<'_>) -> Vec<usize>

Apply this filter against the candidate list. Return the indices to keep (sorted ascending, distinct, in-range).

Source

fn classification(&self) -> FilterClass

Is this a hard filter (may filter to zero, surfaces as error) or soft (may only filter if at least min_remaining remain)?

Source

fn name(&self) -> &'static str

Short identifier shown in diagnostics. Convention: short kebab-case (“precision-floor”, “strided-input-pref”, “judge-fastest”). Used in fuel_ir::Error::FilterRejected.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§