Skip to main content

CandidateGenerator

Trait CandidateGenerator 

Source
pub trait CandidateGenerator: Send + Sync {
    // Required method
    fn generate(&self, ctx: &GenerateContext<'_>) -> Vec<RawCandidate>;

    // Provided methods
    fn cache_key(&self, _ctx: &GenerateContext<'_>) -> Option<CacheKey> { ... }
    fn cache_ttl(&self) -> Duration { ... }
}
Expand description

Produces raw candidates for a slot. Implementations vary from pure (gen:commands walks the registry) to side-effecting (gen:files reads the filesystem). Caching is opt-in via Self::cache_key – the default is “no cache”.

Required Methods§

Provided Methods§

Source

fn cache_key(&self, _ctx: &GenerateContext<'_>) -> Option<CacheKey>

Optional cache key. When two contexts produce the same Some(key), the pipeline serves the second from cache. The query (prefix) is implicitly part of the key only if the generator includes it – many generators key on a registry version (cache covers all queries until the registry changes) and let the matcher do the per-query filtering.

Source

fn cache_ttl(&self) -> Duration

Soft TTL for cache entries. After elapsing, the entry is regenerated on next access. Defaults to no expiry.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§