Struct lib_config::Section
source · pub struct Section<T: ?Sized + Borrow<JObject>>(_);Expand description
Part of a Config object, may contain sub-sections
Implementations§
source§impl<T: ?Sized + Borrow<JObject>> Section<T>
impl<T: ?Sized + Borrow<JObject>> Section<T>
sourcepub fn read_value<K, V>(&self, key: &K) -> Result<V, Box<dyn Error>>where
K: ?Sized + Ord + Eq + Hash,
String: Borrow<K>,
V: DeserializeOwned,
pub fn read_value<K, V>(&self, key: &K) -> Result<V, Box<dyn Error>>where K: ?Sized + Ord + Eq + Hash, String: Borrow<K>, V: DeserializeOwned,
Reads a value from the given key, if the key does not exist returns Err
sourcepub fn get_section<K>(
&self,
key: &K
) -> Result<Section<&JObject>, Box<dyn Error>>where
K: ?Sized + Ord + Eq + Hash,
String: Borrow<K>,
pub fn get_section<K>( &self, key: &K ) -> Result<Section<&JObject>, Box<dyn Error>>where K: ?Sized + Ord + Eq + Hash, String: Borrow<K>,
Gets an immutable reference to Section at the given key
sourcepub fn clone_data(&self) -> JObject
pub fn clone_data(&self) -> JObject
Clones the Section data, the result does not have any reference to the original Config nor Section
source§impl<T: ?Sized + BorrowMut<JObject>> Section<T>
impl<T: ?Sized + BorrowMut<JObject>> Section<T>
sourcepub fn write_value<K: Into<String>, V: Serialize>(
&mut self,
key: K,
value: V
) -> Result<(), Box<dyn Error>>
pub fn write_value<K: Into<String>, V: Serialize>( &mut self, key: K, value: V ) -> Result<(), Box<dyn Error>>
Writes a valute to the given key, if it doesn’t exist, inserts the key - value pair
sourcepub fn read_or_insert<K: Into<String>, V: DeserializeOwned + Serialize + Clone>(
&mut self,
key: K,
value: V
) -> Result<V, Box<dyn Error>>
pub fn read_or_insert<K: Into<String>, V: DeserializeOwned + Serialize + Clone>( &mut self, key: K, value: V ) -> Result<V, Box<dyn Error>>
Reads a value from the given key, if the key does not exists, inserts it with the given value
sourcepub fn update_value<K, V, Out, F>(
&mut self,
key: &K,
f_upd: F
) -> Result<Out, Box<dyn Error>>where
K: ?Sized + Ord + Eq + Hash,
String: Borrow<K>,
V: DeserializeOwned,
Out: Serialize,
F: FnOnce(&V) -> Out,
pub fn update_value<K, V, Out, F>( &mut self, key: &K, f_upd: F ) -> Result<Out, Box<dyn Error>>where K: ?Sized + Ord + Eq + Hash, String: Borrow<K>, V: DeserializeOwned, Out: Serialize, F: FnOnce(&V) -> Out,
Updates a value with the given key using the provided function, returns the final value of the key, if the key does not exist returns Err
Trait Implementations§
Auto Trait Implementations§
impl<T: ?Sized> RefUnwindSafe for Section<T>where T: RefUnwindSafe,
impl<T: ?Sized> Send for Section<T>where T: Send,
impl<T: ?Sized> Sync for Section<T>where T: Sync,
impl<T: ?Sized> Unpin for Section<T>where T: Unpin,
impl<T: ?Sized> UnwindSafe for Section<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more