Skip to main content

Collect

Trait Collect 

Source
pub trait Collect: Send + Sync {
    // Required method
    fn collect(&self, record: &Record);

    // Provided method
    fn flush(&self) { ... }
}
Expand description

Trait for data collectors

Required Methods§

Source

fn collect(&self, record: &Record)

Process a collected data record

Provided Methods§

Source

fn flush(&self)

Flush any buffered data (optional)

Examples found in repository?
examples/file_collector.rs (line 87)
86    fn drop(&mut self) {
87        self.flush();
88    }
89}
90
91fn main() -> Result<(), Box<dyn std::error::Error>> {
92    println!("Data Hook Example with File Collector");
93    println!("=====================================");
94    
95    // Create and set up the file collector
96    let collector = FileCollector::new("data_output")?;
97    let collector: &'static FileCollector = Box::leak(Box::new(collector));
98    set_collector(collector);
99    
100    println!("Initialized file collector. Data will be saved to 'data_output' directory.");
101    
102    // Simulate some application events
103    simulate_user_actions();
104    simulate_performance_metrics();
105    simulate_error_events();
106    
107    // Flush any remaining data
108    collector.flush();
109    
110    println!("\nExample completed! Check the 'data_output' directory for collected data files:");
111    println!("- user_action.jsonl - User interaction events");
112    println!("- performance.jsonl - Performance metrics");
113    println!("- error.jsonl - Error events");
114    
115    Ok(())
116}

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§