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§
Sourcefn compute(
&self,
ctx: &SampleContext<'_>,
) -> Result<Option<Value>, SamplerError>
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§
Sourcefn selector(&self) -> NodeSelector
fn selector(&self) -> NodeSelector
Which nodes this sampler operates on.
Sourcefn sample(
&self,
graph: &SourceCodeGraph,
annotations: &AnnotationMap,
) -> Result<SampleResult, SamplerError>
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".