Skip to content

Commit 2219720

Browse files
cursoragentscript3r
andcommitted
Refactor: Implement producer-consumer scanner architecture
Co-authored-by: script3r <[email protected]>
1 parent 4994956 commit 2219720

File tree

2 files changed

+339
-89
lines changed

2 files changed

+339
-89
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! Basic usage example for the high-performance scanner-core
2+
//!
3+
//! This example demonstrates how to use the refactored scanner with the new
4+
//! producer-consumer architecture.
5+
6+
use scanner_core::{Config, PatternRegistry, Scanner};
7+
use std::path::PathBuf;
8+
use std::sync::Arc;
9+
10+
fn main() -> anyhow::Result<()> {
11+
// Load pattern registry from TOML file
12+
let patterns_toml = r#"
13+
[version]
14+
schema = "1.0"
15+
updated = "2024-01-01"
16+
17+
[[library]]
18+
name = "example-lib"
19+
languages = ["rust", "go", "java"]
20+
21+
[library.patterns]
22+
import = ["use\\s+example_lib"]
23+
apis = ["example_lib::\\w+"]
24+
"#;
25+
26+
let registry = PatternRegistry::load(patterns_toml)?;
27+
28+
// Create configuration
29+
let config = Config {
30+
max_file_size: 2 * 1024 * 1024, // 2MB
31+
include_globs: vec![
32+
"**/*.rs".to_string(),
33+
"**/*.go".to_string(),
34+
"**/*.java".to_string(),
35+
],
36+
exclude_globs: vec![],
37+
deterministic: true,
38+
progress_callback: Some(Arc::new(|processed, discovered, findings| {
39+
println!("Progress: {}/{} files processed, {} findings", processed, discovered, findings);
40+
})),
41+
};
42+
43+
// Create scanner with empty detectors for this example
44+
let detectors = vec![];
45+
let scanner = Scanner::new(&registry, detectors, config);
46+
47+
// Scan the current directory
48+
let roots = vec![PathBuf::from(".")];
49+
let findings = scanner.run(&roots)?;
50+
51+
println!("Scan completed! Found {} findings", findings.len());
52+
for finding in findings.iter().take(5) { // Show first 5 findings
53+
println!(" {} in {:?} at line {}",
54+
finding.library,
55+
finding.file,
56+
finding.span.line);
57+
}
58+
59+
Ok(())
60+
}

0 commit comments

Comments
 (0)