Skip to main content

Section

Struct Section 

Source
pub struct Section<'a> { /* private fields */ }
Expand description

One map of the tree, read under a dotted prefix.

Implementations§

Source§

impl<'a> Section<'a>

Source

pub fn root(node: Option<&'a Node>) -> Result<Self, ConfigError>

The root of a tree (None = nothing was loaded: every read is absent).

§Errors

ConfigError::Invalid when the root is not a map.

Source

pub fn of( node: Option<&'a Node>, prefix: impl Into<String>, ) -> Result<Self, ConfigError>

node as a section named prefix.

§Errors

ConfigError::Invalid when node is not a map.

Source

pub fn path_of(&self, key: &str) -> String

The dotted path of key in this section, for a caller’s own refusal.

Source

pub fn node(&self, key: &str) -> Option<&'a Node>

The raw node at key.

Source

pub fn only(&self, allowed: &[&str]) -> Result<(), ConfigError>

Refuses every key that allowed does not name.

§Errors

ConfigError::Invalid for the first unknown key, with its origin.

Source

pub fn section(&self, key: &str) -> Result<Section<'a>, ConfigError>

The nested section at key.

§Errors

ConfigError::Invalid when it is not a map.

Source

pub fn scalar( &self, key: &str, ) -> Result<Option<(&'a str, &'a Origin)>, ConfigError>

The scalar at key and where it came from.

§Errors

ConfigError::Invalid when key holds a list or a map.

Source

pub fn string(&self, key: &str) -> Result<Option<String>, ConfigError>

The text at key.

§Errors

As Self::scalar.

Source

pub fn parse<T: FromStr>( &self, key: &str, expect: &str, ) -> Result<Option<T>, ConfigError>

The value at key, parsed; expect says what the setting accepts.

§Errors

As Self::scalar, and ConfigError::Invalid when it does not parse.

Source

pub fn boolean(&self, key: &str) -> Result<Option<bool>, ConfigError>

true/false (or 1/0) at key.

§Errors

ConfigError::Invalid for any other spelling.

Source

pub fn choice( &self, key: &str, choices: &[&str], ) -> Result<Option<String>, ConfigError>

One of choices at key.

§Errors

ConfigError::Invalid for anything else.

Source

pub fn strings(&self, key: &str) -> Result<Option<Vec<String>>, ConfigError>

A list of texts at key: a sequence of scalars, or one scalar as a list of one.

§Errors

ConfigError::Invalid for a map or a sequence holding one.

Source

pub fn items(&self, key: &str) -> Result<Vec<(String, &'a Node)>, ConfigError>

The items of the sequence at key, each with its dotted path.

§Errors

ConfigError::Invalid when key is not a sequence.

Trait Implementations§

Source§

impl<'a> Clone for Section<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Section<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Section<'a>

§

impl<'a> RefUnwindSafe for Section<'a>

§

impl<'a> Send for Section<'a>

§

impl<'a> Sync for Section<'a>

§

impl<'a> Unpin for Section<'a>

§

impl<'a> UnsafeUnpin for Section<'a>

§

impl<'a> UnwindSafe for Section<'a>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.