pub trait Scanner: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn scan<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
input: &'life1 str,
vault: &'life2 Vault,
) -> Pin<Box<dyn Future<Output = Result<ScanResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn scanner_type(&self) -> ScannerType { ... }
fn version(&self) -> &str { ... }
fn description(&self) -> &str { ... }
fn requires_async(&self) -> bool { ... }
fn validate_config(&self) -> Result<()> { ... }
}Expand description
Core scanner trait
All security scanners implement this trait to provide consistent interface.
§London School TDD Design
This trait is designed to be mockable for testing:
- Pure async interface
- No internal state mutations
- Testable with mock vault
§Example
ⓘ
use llm_shield_core::{Scanner, ScanResult, Vault};
use async_trait::async_trait;
struct MyScanner;
#[async_trait]
impl Scanner for MyScanner {
fn name(&self) -> &str {
"my_scanner"
}
async fn scan(&self, input: &str, vault: &Vault) -> Result<ScanResult> {
// Implement scanning logic
Ok(ScanResult::pass(input.to_string()))
}
fn scanner_type(&self) -> ScannerType {
ScannerType::Input
}
}Required Methods§
Provided Methods§
Sourcefn scanner_type(&self) -> ScannerType
fn scanner_type(&self) -> ScannerType
Type of scanner (input/output/bidirectional)
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Scanner description
Sourcefn requires_async(&self) -> bool
fn requires_async(&self) -> bool
Whether this scanner requires async execution
Some scanners (e.g., URL checking) must be async. Simple scanners can be sync for better performance.
Sourcefn validate_config(&self) -> Result<()>
fn validate_config(&self) -> Result<()>
Validate scanner configuration