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_str<V>(&self, input: &str) -> Result<V, StorageError>
where V: for<'a> Deserialize<'a>;
// 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§
Sourcefn 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.
Sourcefn 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.
Sourcefn from_str<V>(&self, input: &str) -> Result<V, StorageError>where
V: for<'a> Deserialize<'a>,
fn from_str<V>(&self, input: &str) -> Result<V, StorageError>where
V: for<'a> Deserialize<'a>,
Deserialize the given value from a string
Provided Methods§
Sourcefn 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.
Sourcefn 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.
Sourcefn 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.
Sourcefn 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.