pub trait ChunkProcessor: Send + Sync {
// Required methods
fn process_chunk(
&self,
chunk: &FileChunk,
) -> Result<FileChunk, PipelineError>;
fn name(&self) -> &str;
fn modifies_data(&self) -> bool;
// Provided method
fn requires_sequential_processing(&self) -> bool { ... }
}Expand description
Trait for processing individual file chunks
§Developer Notes - Immutable Processing Pattern
This trait follows DDD Value Object principles where FileChunk is immutable. Instead of mutating chunks, processors return new chunk instances. This ensures data integrity and prevents accidental mutations.
§Architecture Note - Synchronous Domain Service
This trait is synchronous following DDD principles. Chunk processing is CPU-bound (compression, encryption, checksums), not I/O-bound. The domain layer defines what operations exist, not how they execute.
For async contexts, infrastructure adapters can wrap chunk processors
using tokio::spawn_blocking or similar mechanisms.
§Usage Pattern:
Required Methods§
Sourcefn process_chunk(&self, chunk: &FileChunk) -> Result<FileChunk, PipelineError>
fn process_chunk(&self, chunk: &FileChunk) -> Result<FileChunk, PipelineError>
Processes a single chunk of data and returns a new processed chunk
§Arguments
chunk- The input chunk to process (immutable reference)
§Returns
Ok(FileChunk)- New chunk with processing resultsErr(PipelineError)- Processing failed
§Developer Notes
- Input chunk is never modified (immutability)
- Return new chunk with changes applied
- Use chunk.with_data() or chunk.with_checksum() for modifications
§Note on Async
This method is synchronous (CPU-bound operations). For async contexts,
use infrastructure adapters that wrap this in tokio::spawn_blocking.
Sourcefn modifies_data(&self) -> bool
fn modifies_data(&self) -> bool
Returns whether this processor modifies chunk data
Provided Methods§
Sourcefn requires_sequential_processing(&self) -> bool
fn requires_sequential_processing(&self) -> bool
Returns whether this processor requires sequential processing