Module value_objects

Module value_objects 

Source
Expand description

§Domain Value Objects

This module contains the domain value objects - immutable objects that represent concepts without identity. Value objects are defined by their attributes and enforce business rules through validation.

§Value Object Characteristics

All value objects in this system share these characteristics:

  • Immutability: Cannot be modified after creation
  • No Identity: Equality is based on attributes, not identity
  • Self-Validating: Enforce business rules during construction
  • Side-Effect Free: Operations don’t modify state
  • Composable: Can be combined to create more complex concepts

§Core Value Objects

§Identifiers

Strongly-typed identifiers that prevent mixing different types of IDs:

§File Processing Objects

Objects representing file data and processing concepts:

  • FileChunk: Immutable file chunk with integrity validation
  • ChunkMetadata: Metadata for tracking and managing file chunks
  • ChunkSize: Type-safe chunk size with validation and optimization
  • GenericSize: Generic size value object with unit conversions

§Algorithm and Configuration Objects

Objects representing processing algorithms and their configurations:

§File System Objects

Objects representing file paths and permissions with type safety:

  • FilePath: Type-safe file paths with category-specific validation
  • FilePermissions: Cross-platform file permission management

§Binary Format Objects

Objects representing the structure of processed files:

§Security Objects

Objects representing security contexts and permissions:

§Processing Configuration Objects

Objects representing processing parameters and requirements:

§Validation and Business Rules

Value objects enforce business rules through validation:

§Validation Benefits

  • Early Error Detection: Invalid values caught at construction
  • No Invalid States: Impossible to create invalid value objects
  • Clear Error Messages: Descriptive validation errors
  • Type Safety: Compiler enforces validation requirements

§Composition and Transformation

Value objects can be composed and transformed safely:

§Transformation Patterns

  • Immutable Transformations: Create new value objects instead of mutating
  • Builder Pattern: Fluent construction of complex value objects
  • Composition: Combine simple value objects into complex ones
  • Type Conversion: Safe conversion between related types

§Serialization and Persistence

Value objects support serialization for persistence and communication:

§Serialization Features

  • JSON Support: All value objects implement Serialize and Deserialize
  • Type Safety: Deserialization validates constraints
  • Cross-Platform: Consistent representation across languages
  • Version Compatibility: Serialization format stability

§Testing Value Objects

Value objects are easily testable due to their immutability:

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_value_object_equality() {
        let id1 = String::new("test-pipeline").unwrap();
        let id2 = String::new("test-pipeline").unwrap();
        let id3 = String::new("other-pipeline").unwrap();

        // Equality based on value, not identity
        assert_eq!(id1, id2);
        assert_ne!(id1, id3);
    }

    #[test]
    fn test_value_object_immutability() {
        let size = String::new(1024).unwrap();
        let doubled = size.multiply(2).unwrap();

        // Original value unchanged
        assert_eq!(size.as_bytes(), 1024);
        assert_eq!(doubled.as_bytes(), 2048);
    }

    #[test]
    fn test_value_object_validation() {
        // Valid values succeed
        assert!(String::new(1024).is_ok());

        // Invalid values fail
        assert!(String::new(0).is_err());
    }
}

Re-exports§

pub use algorithm::Algorithm;
pub use binary_file_format::ChunkFormat;
pub use binary_file_format::FileHeader;
pub use binary_file_format::ProcessingStepType;
pub use chunk_metadata::ChunkMetadata;
pub use chunk_size::ChunkSize;
pub use encryption_benchmark::EncryptionBenchmark;
pub use encryption_key_id::EncryptionKeyId;
pub use file_chunk::FileChunk;
pub use file_chunk_id::FileChunkId;
pub use file_path::FilePath;
pub use file_permissions::FilePermissions;
pub use generic_id::GenericId;
pub use generic_size::GenericSize;
pub use pipeline_id::PipelineId;
pub use pipeline_requirements::PipelineRequirements;
pub use processing_context_id::ProcessingContextId;
pub use processing_step_descriptor::ProcessingStepDescriptor;
pub use security_context_id::SecurityContextId;
pub use session_id::SessionId;
pub use stage_id::StageId;
pub use stage_order::StageOrder;
pub use stage_parameters::StageParameters;
pub use user_id::UserId;
pub use worker_count::WorkerCount;

Modules§

algorithm
Algorithm Value Object
binary_file_format
Binary File Format Value Object
chunk_metadata
Chunk Metadata Value Object
chunk_size
Chunk Size Value Object
encryption_benchmark
Encryption Benchmark Value Object
encryption_key_id
Encryption Key Identifier Value Object - Security Infrastructure
file_chunk
File Chunk Value Object
file_chunk_id
File Chunk Identifier Value Object - Processing Infrastructure
file_path
File Path Value Object
file_permissions
File Permissions Value Objects
generic_id
Generic ID Value Object
generic_size
Generic Size Value Object
pipeline_id
Pipeline Identifier Value Object - Core Infrastructure
pipeline_requirements
Pipeline Requirements Value Object
processing_context_id
Processing Context Identifier Value Object - Request Tracing Infrastructure
processing_step_descriptor
Processing Step Descriptor Value Object
security_context_id
Security Context Identifier Value Object - Security Infrastructure
session_id
Session Identifier Value Object - Session Management Infrastructure
stage_id
Stage Identifier Value Object - Pipeline Stage Management Infrastructure
stage_order
Stage Order Value Object - Pipeline Stage Sequencing Infrastructure
stage_parameters
Stage Parameters Value Object - Pipeline Configuration Infrastructure
user_id
User ID Value Object - Authentication and Authorization Infrastructure
worker_count
Worker Count Value Object - Parallel Processing Optimization Infrastructure