Trait FileBasedStorage

Source
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§

Source

const EXTENSION: &'static str

The suffix which is used to distinguish this storage solution from others.

Required Methods§

Source

fn get_path(&self) -> &Path

Get path where results are stored.

Source

fn get_storage_instance(&self) -> u64

Get the number of this storage instance. This value may coincide with the thread number.

Source

fn to_writer_pretty<V, W>( &self, writer: W, value: &V, ) -> Result<(), StorageError>
where V: Serialize, W: Write,

Writes either BatchSaveFormat or CombinedSaveFormat to the disk.

Source

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§

Source

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.

Source

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.

Source

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.

Source

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.

Implementors§

Source§

impl<Id, Element> FileBasedStorage<Id, Element> for JsonStorageInterface<Id, Element>

Source§

const EXTENSION: &'static str = "json"

Source§

impl<Id, Element> FileBasedStorage<Id, Element> for RonStorageInterface<Id, Element>

Source§

const EXTENSION: &'static str = "ron"