pub struct Table<V>where
V: PrimaryKey + Serialize,
V::PrimaryKeyType: Ord + FromStr + Display + Debug + Clone,
<<V as PrimaryKey>::PrimaryKeyType as FromStr>::Err: Display,{ /* private fields */ }Expand description
Represents a database table utilizing a BTreeMap for underlying data storage.
Human-readable serializers (e.g., JSON) see it as a map with string keys.
Binary serializers (e.g., bincode) see it as a sequence of rows.
Implementations§
Source§impl<V> Table<V>where
V: PrimaryKey + Serialize + for<'a> Deserialize<'a>,
V::PrimaryKeyType: Ord + FromStr + Display + Debug + Clone,
<<V as PrimaryKey>::PrimaryKeyType as FromStr>::Err: Display,
impl<V> Table<V>where
V: PrimaryKey + Serialize + for<'a> Deserialize<'a>,
V::PrimaryKeyType: Ord + FromStr + Display + Debug + Clone,
<<V as PrimaryKey>::PrimaryKeyType as FromStr>::Err: Display,
Sourcepub fn add(&mut self, value: V) -> Option<V>
pub fn add(&mut self, value: V) -> Option<V>
Adds an entry to the table, returns the value or None if the addition failed
Sourcepub fn get(&self, key: &V::PrimaryKeyType) -> Option<&V>
pub fn get(&self, key: &V::PrimaryKeyType) -> Option<&V>
Gets an entry from the table, returns the value or None if it couldn’t find the data
Sourcepub fn get_mut(&mut self, key: &V::PrimaryKeyType) -> Option<&mut V>
pub fn get_mut(&mut self, key: &V::PrimaryKeyType) -> Option<&mut V>
Gets a mutable entry from the table, returns the value or None if it couldn’t find the data
Sourcepub fn edit(&mut self, key: &V::PrimaryKeyType, new_value: V) -> Option<V>
pub fn edit(&mut self, key: &V::PrimaryKeyType, new_value: V) -> Option<V>
Edits an entry in the table, returns the new_value or None if the editing failed
Sourcepub fn delete(&mut self, key: &V::PrimaryKeyType) -> Option<V>
pub fn delete(&mut self, key: &V::PrimaryKeyType) -> Option<V>
Deletes an entry from the table, returns the value or None if the deletion failed
Sourcepub fn search_ordered<F, O>(&self, predicate: F, comparator: O) -> Vec<&V>
pub fn search_ordered<F, O>(&self, predicate: F, comparator: O) -> Vec<&V>
Searches the table by a predicate function and a custom ordering with a comparator function
Sourcepub fn values(&self) -> Values<'_, V::PrimaryKeyType, V>
pub fn values(&self) -> Values<'_, V::PrimaryKeyType, V>
Gets an iterator over the values of the map, in order by key.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, V::PrimaryKeyType, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, V::PrimaryKeyType, V>
Gets a mutable iterator over the values of the map, in order by key.