pub struct AnalyzerContext { /* private fields */ }Expand description
Context that stores the results of analyzer computations.
The AnalyzerContext provides a centralized storage for metrics computed by different analyzers, allowing for efficient access and serialization of results.
§Example
use term_guard::analyzers::{AnalyzerContext, MetricValue};
let mut context = AnalyzerContext::new();
// Store metrics from different analyzers
context.store_metric("size", MetricValue::Long(1000));
context.store_metric("completeness.user_id", MetricValue::Double(0.98));
// Retrieve metrics
if let Some(size) = context.get_metric("size") {
println!("Dataset size: {}", size);
}
// Get all metrics for a specific analyzer
let completeness_metrics = context.get_analyzer_metrics("completeness");Implementations§
Source§impl AnalyzerContext
impl AnalyzerContext
Sourcepub fn with_dataset(dataset_name: impl Into<String>) -> Self
pub fn with_dataset(dataset_name: impl Into<String>) -> Self
Creates a new context with the given dataset name.
Sourcepub fn store_metric(&mut self, key: impl Into<String>, value: MetricValue)
pub fn store_metric(&mut self, key: impl Into<String>, value: MetricValue)
Stores a metric value with the given key.
§Arguments
key- The metric key, typically in format “analyzer_name.metric_name”value- The metric value to store
Sourcepub fn store_analyzer_metric(
&mut self,
analyzer_name: &str,
metric_name: &str,
value: MetricValue,
)
pub fn store_analyzer_metric( &mut self, analyzer_name: &str, metric_name: &str, value: MetricValue, )
Stores a metric with a composite key built from analyzer and metric names.
§Arguments
analyzer_name- The name of the analyzermetric_name- The name of the specific metricvalue- The metric value to store
Sourcepub fn get_metric(&self, key: &str) -> Option<&MetricValue>
pub fn get_metric(&self, key: &str) -> Option<&MetricValue>
Retrieves a metric value by key.
Sourcepub fn get_analyzer_metrics(
&self,
analyzer_name: &str,
) -> HashMap<String, &MetricValue>
pub fn get_analyzer_metrics( &self, analyzer_name: &str, ) -> HashMap<String, &MetricValue>
Retrieves all metrics for a specific analyzer.
Returns metrics whose keys start with the analyzer name followed by a dot.
Sourcepub fn all_metrics(&self) -> &HashMap<String, MetricValue>
pub fn all_metrics(&self) -> &HashMap<String, MetricValue>
Returns all stored metrics.
Sourcepub fn record_error(
&mut self,
analyzer_name: impl Into<String>,
error: AnalyzerError,
)
pub fn record_error( &mut self, analyzer_name: impl Into<String>, error: AnalyzerError, )
Records an error that occurred during analysis.
Sourcepub fn errors(&self) -> &[AnalysisError]
pub fn errors(&self) -> &[AnalysisError]
Returns all recorded errors.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Checks if any errors occurred during analysis.
Sourcepub fn metadata(&self) -> &AnalysisMetadata
pub fn metadata(&self) -> &AnalysisMetadata
Returns the analysis metadata.
Sourcepub fn metadata_mut(&mut self) -> &mut AnalysisMetadata
pub fn metadata_mut(&mut self) -> &mut AnalysisMetadata
Returns a mutable reference to the analysis metadata.
Sourcepub fn merge(&mut self, other: AnalyzerContext)
pub fn merge(&mut self, other: AnalyzerContext)
Merges another context into this one.
Metrics from the other context will overwrite existing metrics with the same key.
Sourcepub fn summary(&self) -> AnalysisSummary
pub fn summary(&self) -> AnalysisSummary
Creates a summary of the analysis results.
Trait Implementations§
Source§impl Clone for AnalyzerContext
impl Clone for AnalyzerContext
Source§fn clone(&self) -> AnalyzerContext
fn clone(&self) -> AnalyzerContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AnalyzerContext
impl Debug for AnalyzerContext
Source§impl Default for AnalyzerContext
impl Default for AnalyzerContext
Source§impl<'de> Deserialize<'de> for AnalyzerContext
impl<'de> Deserialize<'de> for AnalyzerContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for AnalyzerContext
impl RefUnwindSafe for AnalyzerContext
impl Send for AnalyzerContext
impl Sync for AnalyzerContext
impl Unpin for AnalyzerContext
impl UnwindSafe for AnalyzerContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more