Expand description
Core types and scanning primitives for cloakrs.
cloakrs-core contains the public data model, recognizer trait,
registry, scanner, and masking strategy implementations shared by the
rest of the workspace.
§Examples
use cloakrs_core::{Confidence, EntityType, Locale, PiiEntity, Recognizer, Scanner, Span};
struct Email;
impl Recognizer for Email {
fn id(&self) -> &str { "email_example_v1" }
fn entity_type(&self) -> EntityType { EntityType::Email }
fn supported_locales(&self) -> &[Locale] { &[] }
fn scan(&self, text: &str) -> Vec<PiiEntity> {
text.find('@').map(|_| PiiEntity {
entity_type: EntityType::Email,
span: Span::new(0, text.len()),
text: text.to_string(),
confidence: Confidence::new(0.9).unwrap(),
recognizer_id: self.id().to_string(),
}).into_iter().collect()
}
}
let scanner = Scanner::builder().recognizer(Email).build().unwrap();
let result = scanner.scan("jane@example.com").unwrap();
assert_eq!(result.masked_text.as_deref(), Some("[EMAIL]"));Structs§
- Confidence
- Confidence score wrapper guaranteed to contain a value from
0.0to1.0. - Context
Config - Configuration for context-aware confidence scoring.
- Context
Score - Result of context scoring.
- Context
Window - Words surrounding a candidate match.
- PiiEntity
- A detected PII entity within text.
- Recognizer
Registry - Registry that holds active recognizers.
- Scan
Result - Result of scanning text.
- Scan
Stats - Statistics about a scan.
- Scanner
- The main scanner that ties detection and masking together.
- Scanner
Builder - Builder for configuring a
Scanner. - Span
- Byte offset range in source text, using
[start, end).
Enums§
- Cloak
Error - Errors produced by cloakrs core APIs.
- Entity
Type - All supported PII entity types.
- Locale
- Locale selector used to choose locale-specific recognizers.
- Mask
Strategy - How detected PII should be masked.
Traits§
- Recognizer
- A recognizer that can detect a specific type of PII.
Functions§
- apply_
mask - Applies a masking strategy to text using the supplied findings.
- context_
score - Computes a bounded context confidence adjustment.
- decrypt_
masked_ value - Decrypts a value produced by
MaskStrategy::Encrypt. - surrounding_
context - Extracts lowercased words before and after a candidate span.
Type Aliases§
- Result
- Convenient result alias for cloakrs operations.