pub trait Analyzer: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn config(&self) -> &AnalyzerConfig;
fn state(&self) -> AnalyzerState;
fn start<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn process_event<'life0, 'async_trait>(
&'life0 mut self,
event: AnalyzerEvent,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn generate_report<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<AnalysisReport>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn get_stats(&self) -> AnalyzerStats;
fn reset<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Core trait that all analyzers must implement
This trait defines the interface for real-time analysis of LLM optimization metrics. Analyzers receive events, maintain state, perform analysis, and generate reports with insights and recommendations.
Required Methods§
Sourcefn config(&self) -> &AnalyzerConfig
fn config(&self) -> &AnalyzerConfig
Get the analyzer’s configuration
Sourcefn state(&self) -> AnalyzerState
fn state(&self) -> AnalyzerState
Get the current state of the analyzer
Sourcefn start<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Start the analyzer
This initializes internal state and prepares the analyzer to receive events.
§Errors
Returns an error if the analyzer is already running or if initialization fails.
Sourcefn stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stop the analyzer gracefully
This drains any remaining events and performs cleanup.
§Errors
Returns an error if the analyzer is already stopped or if cleanup fails.
Sourcefn process_event<'life0, 'async_trait>(
&'life0 mut self,
event: AnalyzerEvent,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn process_event<'life0, 'async_trait>(
&'life0 mut self,
event: AnalyzerEvent,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Process a single event
This is the core analysis method that processes incoming events. The analyzer updates its internal state and may generate insights immediately or batch them for the next report.
§Arguments
event- The event to process
§Returns
Returns Ok(()) if the event was processed successfully.
§Errors
Returns an error if:
- The analyzer is not in the
Runningstate - The event is invalid
- Internal processing fails
Sourcefn generate_report<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<AnalysisReport>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn generate_report<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<AnalysisReport>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generate a report of current analysis results
This method returns the current state of analysis, including any insights, recommendations, and alerts generated since the last report.
§Returns
Returns a report containing:
- Summary statistics
- Insights discovered
- Recommendations generated
- Alerts triggered
§Errors
Returns an error if report generation fails.
Sourcefn get_stats(&self) -> AnalyzerStats
fn get_stats(&self) -> AnalyzerStats
Get current statistics about the analyzer’s operation
This includes metrics like:
- Events processed
- Analysis duration
- Memory usage
- Error counts
Sourcefn reset<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn reset<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Reset the analyzer’s state
This clears all accumulated state and resets counters. The analyzer remains in its current lifecycle state.
§Errors
Returns an error if reset fails.
Sourcefn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AnalyzerResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Health check for the analyzer
Returns Ok(()) if the analyzer is healthy and able to process events.
§Errors
Returns an error if:
- Memory usage exceeds limits
- Error rate is too high
- Internal state is corrupted
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".