bubbles/saliency/candidate.rs
1//! [`Candidate`] and the [`SaliencyStrategy`] trait.
2
3/// A candidate presented to the saliency strategy for selection.
4#[derive(Debug, Clone)]
5pub struct Candidate<'a> {
6 /// Stable id for this variant.
7 pub id: &'a str,
8 /// Whether this candidate is eligible (guard condition passed, not once-exhausted).
9 pub available: bool,
10}
11
12/// Selects one candidate from a list of available variants.
13///
14/// Implement this trait to customise line-group and node-group selection behaviour.
15/// Strategies may be stateful (e.g. tracking which variants have been recently shown).
16pub trait SaliencyStrategy: Send + Sync + 'static {
17 /// Returns the index into `candidates` of the chosen variant, or `None` to skip the group.
18 fn select(&mut self, candidates: &[Candidate<'_>]) -> Option<usize>;
19}