Section

Struct Section 

Source
pub struct Section<T: ?Sized + Borrow<JObject>>(/* private fields */);
Expand description

Part of a Config object, may contain sub-sections

Implementations§

Source§

impl<T: ?Sized + Borrow<JObject>> Section<T>

Source

pub fn read_value<K, V>(&self, key: &K) -> Result<V, 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

Source

pub fn get_section<K>(&self, key: &K) -> Result<Section<&JObject>, Error>
where K: ?Sized + Ord + Eq + Hash, String: Borrow<K>,

Gets an immutable reference to Section at the given key

Source

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>

Source

pub fn write_value<K: Into<String>, V: Serialize>( &mut self, key: K, value: V, ) -> Result<(), Error>

Writes a valute to the given key, if it doesn’t exist, inserts the key value pair

Source

pub fn read_or_insert<K: Into<String>, V: DeserializeOwned + Serialize + Clone>( &mut self, key: K, value: V, ) -> Result<V, Error>

Reads a value from the given key, if the key does not exists, inserts it with the given value

Source

pub fn update_value<K, V, Out, F>( &mut self, key: &K, f_upd: F, ) -> Result<Out, 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

Source

pub fn get_section_mut<K>( &mut self, key: &K, ) -> Result<Section<&mut JObject>, Error>
where K: ?Sized + Ord + Eq + Hash, String: Borrow<K>,

Gets a mutable reference to Section at the given key

§Remarks

Changing the Section’s value will also change the Config data

Source

pub fn copy_from(&mut self, data: JObject)

Replaces Section data with the provided data

Trait Implementations§

Source§

impl<T: Debug + ?Sized + Borrow<JObject>> Debug for Section<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Section<T>
where T: Freeze + ?Sized,

§

impl<T> RefUnwindSafe for Section<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for Section<T>
where T: Send + ?Sized,

§

impl<T> Sync for Section<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for Section<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for Section<T>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.