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>>;

    // Provided methods
    fn supports_streaming(&self) -> bool { ... }
    fn process_stream(
        &self,
        reader: &mut dyn Read,
        writer: &mut dyn Write,
        profile: &FileTypeProfile,
        store: &MappingStore,
    ) -> Result<()> { ... }
}
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.

Provided Methods§

Source

fn supports_streaming(&self) -> bool

Whether this processor supports bounded-memory streaming via process_stream.

Processors that return true here are eligible for the streaming structured path in the CLI, which opens the file as a reader instead of reading it fully into memory. The default is false.

Source

fn process_stream( &self, reader: &mut dyn Read, writer: &mut dyn Write, profile: &FileTypeProfile, store: &MappingStore, ) -> Result<()>

Process content from a reader, writing sanitized output to a writer.

The default implementation reads the entire reader into memory and delegates to process. Processors that return true from supports_streaming should override this to handle data incrementally, keeping memory usage bounded regardless of input size.

§Errors

Returns SanitizeError on read, parse, or write failure.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§