chunkify/chunk/trait.rs
1use crate::*;
2
3/// Trait for generating chunk file names.
4///
5/// Implementations should provide a function that generates unique names for chunk files.
6pub trait ChunkNaming<'a>: Fn(&'a str, usize) -> String + Send + Sync {}
7
8/// Trait for handling chunk operations.
9///
10/// Defines the interface for saving and merging file chunks.
11pub trait HandleStrategy<'a>: Send + Sync {
12 /// Saves a chunk of data.
13 ///
14 /// # Arguments
15 ///
16 /// - `&'a [u8]` - The chunk data to save.
17 /// - `usize` - The chunk index.
18 ///
19 /// # Returns
20 ///
21 /// - `impl Future<Output = ChunkStrategyResult>` - Future of the save operation.
22 fn save_chunk(
23 &self,
24 chunk_data: &'a [u8],
25 chunk_index: usize,
26 ) -> impl Future<Output = ChunkStrategyResult> + Send;
27
28 /// Merges all chunks into the final file.
29 ///
30 /// # Returns
31 ///
32 /// - `impl Future<Output = ChunkStrategyResult>` - Future of the merge operation.
33 fn merge_chunks(&self) -> impl Future<Output = ChunkStrategyResult> + Send;
34}