Trait FileBasedStorage
pub trait FileBasedStorage<Id, Element> {
const EXTENSION: &'static str;
// Required methods
fn get_path(&self) -> &Path;
fn get_storage_instance(&self) -> u64;
fn to_writer_pretty<V, W>(
&self,
writer: W,
value: &V,
) -> Result<(), StorageError>
where V: Serialize,
W: Write;
fn from_reader<V, R>(&self, reader: R) -> Result<V, StorageError>
where V: for<'a> Deserialize<'a>,
R: Read;
// Provided methods
fn create_or_get_iteration_file_with_prefix(
&self,
iteration: u64,
mode: StorageMode,
) -> Result<BufWriter<File>, StorageError> { ... }
fn get_iteration_path(&self, iteration: u64) -> PathBuf { ... }
fn get_iteration_save_path_batch_with_prefix(
&self,
iteration: u64,
mode: StorageMode,
) -> Result<PathBuf, StorageError> { ... }
fn folder_name_to_iteration(
&self,
file: &Path,
) -> Result<Option<u64>, StorageError> { ... }
}
Expand description
Abstraction and simplification of many file-based storage solutions
Required Associated Constants§
Required Methods§
fn get_storage_instance(&self) -> u64
fn get_storage_instance(&self) -> u64
Get the number of this storage instance. This value may coincide with the thread number.
fn to_writer_pretty<V, W>(
&self,
writer: W,
value: &V,
) -> Result<(), StorageError>
fn to_writer_pretty<V, W>( &self, writer: W, value: &V, ) -> Result<(), StorageError>
Writes either BatchSaveFormat or CombinedSaveFormat to the disk.
fn from_reader<V, R>(&self, reader: R) -> Result<V, StorageError>where
V: for<'a> Deserialize<'a>,
R: Read,
fn from_reader<V, R>(&self, reader: R) -> Result<V, StorageError>where
V: for<'a> Deserialize<'a>,
R: Read,
Deserializes the given value type from a reader.
Provided Methods§
fn create_or_get_iteration_file_with_prefix(
&self,
iteration: u64,
mode: StorageMode,
) -> Result<BufWriter<File>, StorageError>
fn create_or_get_iteration_file_with_prefix( &self, iteration: u64, mode: StorageMode, ) -> Result<BufWriter<File>, StorageError>
Creates a new iteration file with a predefined naming scheme.
The path which to use is by default determined by the FileBasedStorage::get_iteration_save_path_batch_with_prefix function.
fn get_iteration_path(&self, iteration: u64) -> PathBuf
fn get_iteration_path(&self, iteration: u64) -> PathBuf
Get the path which holds saved entries if the given iteration.
By default this function joins the path generated by FileBasedStorage::get_path with a 0-delimited number according to the iteration number.
fn get_iteration_save_path_batch_with_prefix(
&self,
iteration: u64,
mode: StorageMode,
) -> Result<PathBuf, StorageError>
fn get_iteration_save_path_batch_with_prefix( &self, iteration: u64, mode: StorageMode, ) -> Result<PathBuf, StorageError>
Creates the path used by the FileBasedStorage::create_or_get_iteration_file_with_prefix function.
fn folder_name_to_iteration(
&self,
file: &Path,
) -> Result<Option<u64>, StorageError>
fn folder_name_to_iteration( &self, file: &Path, ) -> Result<Option<u64>, StorageError>
Converts a given path of a folder to a iteration number.
This function is used for loading results
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.