pub struct MappingStore { /* private fields */ }Expand description
Thread-safe concurrent one-way replacement store.
Caches forward mappings for per-run consistency (same input always produces the same output within a run). There is no reverse map, no journal, and no persistence — replacements are one-way only.
See the module-level documentation for concurrency and memory details.
Implementations§
Source§impl MappingStore
impl MappingStore
Sourcepub fn new(
generator: Arc<dyn ReplacementGenerator>,
capacity_limit: Option<usize>,
) -> Self
pub fn new( generator: Arc<dyn ReplacementGenerator>, capacity_limit: Option<usize>, ) -> Self
Create a new, empty mapping store.
§Arguments
generator— replacement strategy (HMAC or random).capacity_limit— optional max number of unique mappings.
Sourcepub fn get_or_insert(
&self,
category: &Category,
original: &str,
) -> Result<CompactString>
pub fn get_or_insert( &self, category: &Category, original: &str, ) -> Result<CompactString>
Get or create the sanitized replacement for (category, original).
This is the primary API for one-way sanitization.
Thread-safety: Uses DashMap::entry() which holds a shard-level
lock only for the duration of the insert closure. The generator is
called inside the lock, but generation is fast (one HMAC or one RNG
call). Capacity enforcement uses compare_exchange to prevent
TOCTOU over-insertion (C-1 fix).
Per-run consistency: Once a value is mapped, all subsequent lookups return the same sanitized value (first-writer-wins).
§Errors
Returns SanitizeError::CapacityExceeded if the store has
reached its configured capacity limit.
Sourcepub fn forward_lookup(
&self,
category: &Category,
original: &str,
) -> Option<CompactString>
pub fn forward_lookup( &self, category: &Category, original: &str, ) -> Option<CompactString>
Look up an existing forward mapping without creating one.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all mappings, zeroizing the original plaintexts.
This is useful for resetting the store between runs without dropping and recreating it.
Sourcepub fn snapshot_keys(&self) -> HashSet<(Category, String)>
pub fn snapshot_keys(&self) -> HashSet<(Category, String)>
Snapshot the set of (category, original) keys currently in the store.
Call this before structured processing; diff against iter() afterwards
to find which mappings were added by the processor.
Sourcepub fn iter(
&self,
) -> impl Iterator<Item = (Category, CompactString, CompactString)> + '_
pub fn iter( &self, ) -> impl Iterator<Item = (Category, CompactString, CompactString)> + '_
Iterate over all mappings. Yields (category, original, sanitized).
Note: iteration over DashMap is not snapshot-consistent if concurrent
inserts are happening. Call this after all workers have finished.
Trait Implementations§
Source§impl Drop for MappingStore
F-09 fix: zeroize original keys stored in the forward map on drop.
This prevents sensitive plaintext values from lingering on the heap
after the store is no longer needed. Uses safe Zeroize on Strings.
impl Drop for MappingStore
F-09 fix: zeroize original keys stored in the forward map on drop. This prevents sensitive plaintext values from lingering on the heap after the store is no longer needed. Uses safe Zeroize on Strings.
Auto Trait Implementations§
impl !Freeze for MappingStore
impl !RefUnwindSafe for MappingStore
impl Send for MappingStore
impl Sync for MappingStore
impl Unpin for MappingStore
impl UnsafeUnpin for MappingStore
impl !UnwindSafe for MappingStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more