Struct Section

Source
pub struct Section { /* private fields */ }
Expand description

A section containing key-value pairs and nested subsections.

Sections form a hierarchical structure similar to directories, where each section can contain both values and other sections.

Implementations§

Source§

impl Section

Source

pub fn new() -> Self

Create a new empty section.

Source

pub fn get_or_create_value(&mut self, key: &str) -> &mut Value

Get a value by key, creating it if it doesn’t exist.

This is similar to the C++ operator[] behavior.

Source

pub fn at(&self, key: &str) -> Result<&Value>

Get a value by key.

Source

pub fn get_value(&self, key: &str) -> Result<&Value>

Get a value by key.

Source

pub fn get_value_mut(&mut self, key: &str) -> Result<&mut Value>

Get a mutable value by key.

Source

pub fn set_value(&mut self, key: impl Into<String>, value: impl Into<Value>)

Set a value for a key.

Source

pub fn has_value(&self, key: &str) -> bool

Check if a value exists for the given key.

Source

pub fn remove_value(&mut self, key: &str) -> Option<Value>

Remove a value by key.

Source

pub fn get_section(&self, name: &str) -> Result<&Section>

Get a subsection by name.

Source

pub fn section(&mut self, name: &str) -> &mut Section

Get a subsection by name, creating it if it doesn’t exist.

Source

pub fn get_section_mut(&mut self, name: &str) -> Result<&mut Section>

Get a mutable subsection by name.

Source

pub fn has_section(&self, name: &str) -> bool

Check if a subsection exists.

Source

pub fn remove_section(&mut self, name: &str) -> Option<Section>

Remove a subsection by name.

Source

pub fn values(&self) -> impl Iterator<Item = (&String, &Value)>

Iterate over all values in this section.

Source

pub fn values_mut(&mut self) -> impl Iterator<Item = (&String, &mut Value)>

Iterate over all values in this section (mutable).

Source

pub fn sections(&self) -> impl Iterator<Item = (&String, &Section)>

Iterate over all subsections in this section.

Source

pub fn sections_mut(&mut self) -> impl Iterator<Item = (&String, &mut Section)>

Iterate over all subsections in this section (mutable).

Source

pub fn clear(&mut self)

Clear all values and subsections.

Source

pub fn is_empty(&self) -> bool

Check if this section is empty (no values and no subsections).

Source

pub fn value_count(&self) -> usize

Get the number of values in this section.

Source

pub fn section_count(&self) -> usize

Get the number of subsections in this section.

Source

pub fn value_keys(&self) -> impl Iterator<Item = &String>

Get all value keys.

Source

pub fn section_names(&self) -> impl Iterator<Item = &String>

Get all section names.

Trait Implementations§

Source§

impl Clone for Section

Source§

fn clone(&self) -> Section

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Section

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Section

Source§

fn default() -> Section

Returns the “default value” for a type. Read more
Source§

impl Index<&str> for Section

Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<&str> for Section

Source§

fn index_mut(&mut self, key: &str) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for Section

Source§

fn eq(&self, other: &Section) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Section

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.