Skip to main content

Sampler

Trait Sampler 

Source
pub trait Sampler: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn compute(
        &self,
        ctx: &SampleContext<'_>,
    ) -> Result<Option<Value>, SamplerError>;

    // Provided methods
    fn selector(&self) -> NodeSelector { ... }
    fn sample(
        &self,
        graph: &SourceCodeGraph,
        annotations: &AnnotationMap,
    ) -> Result<SampleResult, SamplerError> { ... }
}
Expand description

The core sampling primitive.

A sampler selects nodes from a graph, computes a local function for each, and collects the results into a SampleResult. Samplers are composable: the output of one can be fed into the annotations of the next via SamplerPipeline.

Required Methods§

Source

fn id(&self) -> &str

Stable identifier (used as key in annotation maps and persistence).

Source

fn compute( &self, ctx: &SampleContext<'_>, ) -> Result<Option<Value>, SamplerError>

Compute the artifact for a single node. Return Ok(None) to skip a node without error.

Provided Methods§

Source

fn selector(&self) -> NodeSelector

Which nodes this sampler operates on.

Source

fn sample( &self, graph: &SourceCodeGraph, annotations: &AnnotationMap, ) -> Result<SampleResult, SamplerError>

Run the full sampling pass over a graph.

Default implementation: select → build context → compute → collect. Override only when the sampler needs batch-level optimizations (e.g. batched embedding inference).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§