1b49135ca9
Remove async-trait dependency and use native Rust async fn in traits. Replace Arc<dyn Trait> with Arc<ConcreteType> throughout the codebase to enable monomorphization and eliminate dynamic dispatch overhead. Key changes: - Remove write-behind cache (no implementation existed) - Fix should_transcode static method call - Use ContactStorageAdapter directly instead of dyn AddressBookUseCase - Clean up unused trait imports across services and DI https://claude.ai/code/session_01EbAFEfyJNLRmJHmmYDX3Tt
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
//! Compression Port - Application layer abstraction for compression services.
|
|
//!
|
|
//! This module defines the port (trait) for compression operations,
|
|
//! keeping the application and interface layers independent of specific
|
|
//! compression implementations (gzip, zstd, etc.).
|
|
|
|
use crate::common::errors::DomainError;
|
|
|
|
/// Compression level settings for file compression operations.
|
|
///
|
|
/// These levels control the trade-off between compression speed and ratio.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum CompressionLevel {
|
|
/// No compression (passthrough)
|
|
None = 0,
|
|
/// Fast compression with lower ratio
|
|
Fast = 1,
|
|
/// Balanced compression (default)
|
|
Default = 6,
|
|
/// Maximum compression (slower)
|
|
Best = 9,
|
|
}
|
|
|
|
/// Port for compression/decompression operations.
|
|
///
|
|
/// Implementations of this trait provide the actual compression logic
|
|
/// (e.g., gzip, zstd) while the application layer remains agnostic
|
|
/// of the specific algorithm used.
|
|
pub trait CompressionPort: Send + Sync + 'static {
|
|
/// Compress data in memory.
|
|
async fn compress_data(
|
|
&self,
|
|
data: &[u8],
|
|
level: CompressionLevel,
|
|
) -> Result<Vec<u8>, DomainError>;
|
|
|
|
/// Decompress data in memory.
|
|
async fn decompress_data(&self, compressed_data: &[u8]) -> Result<Vec<u8>, DomainError>;
|
|
|
|
/// Determine if a file should be compressed based on its MIME type and size.
|
|
fn should_compress(&self, mime_type: &str, size: u64) -> bool;
|
|
}
|