Skip to main content

Section

Struct Section 

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

One section of the named group G.

ConfigView::section and ConfigView::sections give a section. In the ostrya crate, RepoConfig::section, RepoConfig::sections, and RepoConfig::resolve also give a section. A read takes a key of the group G alone, and parses the value of the file each time that it is called.

A section of the group remote of the ostrya crate comes from config or from a .conf file of the remotes directory, and source names the file. A section of each other group comes from config.

Implementations§

Source§

impl<'a, G: Group> Section<'a, G>

Source

pub fn name(&self) -> &'a str

Returns the name of the section: SECTION of the header NAME "SECTION".

Source

pub fn source(&self) -> RemoteSource<'a>

Returns the file that holds the section: config, or a .conf file of the remotes directory.

Only a section of the group remote of the ostrya crate can come from a .conf file. A section of each other group, and each section of a ConfigView, gives RemoteSource::Config.

Source

pub fn get<K: Key<G>>(&self) -> Result<K::Output, ConfigError>

Returns the value in effect of the key K: the value of the file, or the default of the key if the file does not set it.

The result type is Key::Output. It is Option<V> for a key with no default that is not required.

§Errors
Source

pub fn file_value<K: Key<G>>(&self) -> Result<Option<K::Value>, ConfigError>

Returns the value of the key K in the file, or None if the file does not set it. The default of the key does not apply.

§Errors

The error of the value type if the value does not parse. ValueError states the text.

Source

pub fn lookup<K: Key<G>>(&self) -> Result<Option<Lookup<K::Value>>, ConfigError>

Returns the value in effect of the key K and its source, or None if the file does not set the key and the key has no default.

A section has no override, so the source is Lookup::File or Lookup::Default.

§Errors

The error of the value type if the value does not parse. ValueError states the text.

Source

pub fn refuse_unknown_keys(&self) -> Result<(), ConfigError>

Refuses a key of the section that the closed group G does not list.

The call checks nothing if Group::CLOSED of G is false. It checks each key against the key list of G alone, and gives the unknown-key text for a key outside the list. It names the first such key in the order of the file. The ostrya crate applies this check to its own closed groups. A library user calls it for a closed group of its own.

For the removed key collection of a client group of the ostrya crate, the call gives the unknown-key text. RepoConfig::check gives a text that starts with [HEADER] holds the removed key 'collection' for this key.

For the keys gpg-verify-summary, sign-verify-summary, and verification-ENGINE-key and verification-ENGINE-file of an engine other than ed25519 and spki in a trust group of the ostrya crate, the call also gives the unknown-key text. RepoConfig::check and the readers of a trust group give a text that states the reason.

§Errors

ConfigError::InvalidFormat with the text [HEADER] holds the unknown key 'KEY', where HEADER is the header of the section.

§Examples
use ostrya_core::KeyFile;
use ostrya_core::config::{ConfigError, ConfigView};

ostrya_core::config_group! {
    pub group image = named "ex-image", closed {
        Arch: Option<String> = "arch";
    }
}

let kf = KeyFile::parse("[ex-image \"base\"]\narch=x86\nzzz=1\n")?;
let view = ConfigView::new(&kf);
let base = view.section::<image::Group>("base").unwrap();
assert_eq!(
    base.refuse_unknown_keys().unwrap_err().to_string(),
    "invalid format: [ex-image \"base\"] holds the unknown key 'zzz'"
);

Trait Implementations§

Source§

impl<G: Group> Clone for Section<'_, G>

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<G: Group> Debug for Section<'_, G>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, G> Forget for Section<'a, G>

§

impl<'a, G> Freeze for Section<'a, G>
where &'a KeyFile: Freeze, &'a str: Freeze, PhantomData<fn() -> G>: Freeze,

§

impl<'a, G> Move for Section<'a, G>

§

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

§

impl<'a, G> Send for Section<'a, G>
where &'a KeyFile: Send, &'a str: Send,

§

impl<'a, G> Sync for Section<'a, G>
where RawVecInner: Sync, RawTable<(String, usize)>: Sync,

§

impl<'a, G> Unpin for Section<'a, G>
where &'a KeyFile: Unpin, &'a str: Unpin,

§

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

§

impl<'a, G> UnwindSafe for Section<'a, G>
where &'a KeyFile: UnwindSafe, &'a str: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.