Skip to main content

Processor

Trait Processor 

Source
pub trait Processor: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn can_handle(&self, content: &[u8], profile: &FileTypeProfile) -> bool;
    fn process(
        &self,
        content: &[u8],
        profile: &FileTypeProfile,
        store: &MappingStore,
    ) -> Result<Vec<u8>>;
}
Expand description

A structured processor that can sanitize a specific file format while preserving its structure and formatting as much as possible.

Processors are stateless — all mutable state lives in the MappingStore they receive. This makes processors Send + Sync and reusable across files.

§Contract

  • name() must return a unique, lowercase identifier (e.g. "json").
  • can_handle() is a fast heuristic check; it may inspect a few bytes or the file extension but should not fully parse.
  • process() performs the full structured sanitization. It should preserve formatting/whitespace where possible and only replace values in fields matched by the profile’s FieldRules.
  • Replacements are one-way via the MappingStore — no reverse mapping is produced.

Required Methods§

Source

fn name(&self) -> &'static str

Unique name for this processor (e.g. "json", "yaml", "key_value").

Source

fn can_handle(&self, content: &[u8], profile: &FileTypeProfile) -> bool

Quick heuristic: can this processor handle the given content?

Implementations may check magic bytes, file extension hints in the profile, or the first few bytes of content. This is called before process() and should be fast.

Source

fn process( &self, content: &[u8], profile: &FileTypeProfile, store: &MappingStore, ) -> Result<Vec<u8>>

Process the content, replacing matched field values one-way.

§Arguments
  • content — raw file bytes.
  • profile — the user-supplied profile with field rules.
  • store — the mapping store for dedup-consistent one-way replacements.
§Returns

The sanitized content as bytes, preserving structure/formatting where possible.

§Errors

Returns SanitizeError if parsing or replacement generation fails.

Implementors§