Trait StorageInterfaceLoad
pub trait StorageInterfaceLoad<Id, Element> {
// Required methods
fn load_single_element(
&self,
iteration: u64,
identifier: &Id,
) -> Result<Option<Element>, StorageError>
where Id: Eq + Serialize + for<'a> Deserialize<'a>,
Element: for<'a> Deserialize<'a>;
fn load_all_elements_at_iteration(
&self,
iteration: u64,
) -> Result<HashMap<Id, Element>, StorageError>
where Id: Hash + Eq + for<'a> Deserialize<'a>,
Element: for<'a> Deserialize<'a>;
fn get_all_iterations(&self) -> Result<Vec<u64>, StorageError>;
// Provided methods
fn load_element_history(
&self,
identifier: &Id,
) -> Result<HashMap<u64, Element>, StorageError>
where Id: Eq + Serialize + for<'a> Deserialize<'a>,
Element: for<'a> Deserialize<'a> { ... }
fn load_all_elements(
&self,
) -> Result<BTreeMap<u64, HashMap<Id, Element>>, StorageError>
where Id: Hash + Eq + for<'a> Deserialize<'a>,
Element: for<'a> Deserialize<'a> { ... }
fn load_all_element_histories(
&self,
) -> Result<HashMap<Id, BTreeMap<u64, Element>>, StorageError>
where Id: Hash + Eq + for<'a> Deserialize<'a>,
Element: for<'a> Deserialize<'a> { ... }
}
Expand description
Handles loading of elements
Required Methods§
fn load_single_element(
&self,
iteration: u64,
identifier: &Id,
) -> Result<Option<Element>, StorageError>
fn load_single_element( &self, iteration: u64, identifier: &Id, ) -> Result<Option<Element>, StorageError>
Loads a single element from the storage solution if the element exists.
fn load_all_elements_at_iteration(
&self,
iteration: u64,
) -> Result<HashMap<Id, Element>, StorageError>
fn load_all_elements_at_iteration( &self, iteration: u64, ) -> Result<HashMap<Id, Element>, StorageError>
Gets a snapshot of all elements at a given iteration.
This function might be useful when implementing how simulations can be restored from saved results.
fn get_all_iterations(&self) -> Result<Vec<u64>, StorageError>
fn get_all_iterations(&self) -> Result<Vec<u64>, StorageError>
Get all iteration values which have been saved.
Provided Methods§
fn load_element_history(
&self,
identifier: &Id,
) -> Result<HashMap<u64, Element>, StorageError>
fn load_element_history( &self, identifier: &Id, ) -> Result<HashMap<u64, Element>, StorageError>
Loads the elements history, meaning every occurrence of the element in the storage. This function by default provides the results in ordered fashion such that the time direction is retained. Furthermore this function assumes that a given index occurs over the course of a complete time segment with no interceptions.
// All elements (given by Strings) occur over a period of time
// but do not appear afterwards.
use std::collections::HashMap;
let valid_state = HashMap::from([
(0, vec!["E1", "E2", "E3"]),
(1, vec!["E1", "E2", "E3", "E4"]),
(2, vec!["E1", "E2", "E3", "E4"]),
(3, vec!["E1", "E2", "E4"]),
(4, vec!["E2", "E4"]),
(5, vec!["E2", "E4", "E5"]),
(6, vec!["E4", "E5"]),
]);
// The entry "E2" is missing in iteration 1 but present afterwards.
// This is an invalid state but will not be caught.
// The backend is responsible to avoid this state.
let invalid_state = HashMap::from([
(0, vec!["E1", "E2"]),
(1, vec!["E1"]),
(2, vec!["E1", "E2"]),
]);
fn load_all_elements(
&self,
) -> Result<BTreeMap<u64, HashMap<Id, Element>>, StorageError>
fn load_all_elements( &self, ) -> Result<BTreeMap<u64, HashMap<Id, Element>>, StorageError>
Loads all elements for every iteration. This will yield the complete storage and may result in extremely large allocations of memory.
fn load_all_element_histories(
&self,
) -> Result<HashMap<Id, BTreeMap<u64, Element>>, StorageError>
fn load_all_element_histories( &self, ) -> Result<HashMap<Id, BTreeMap<u64, Element>>, StorageError>
Similarly to the load_all_elements function, but this function returns all elements as their histories.