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>
impl<'a, G: Group> Section<'a, G>
Sourcepub fn name(&self) -> &'a str
pub fn name(&self) -> &'a str
Returns the name of the section: SECTION of the header
NAME "SECTION".
Sourcepub fn source(&self) -> RemoteSource<'a>
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.
Sourcepub fn get<K: Key<G>>(&self) -> Result<K::Output, ConfigError>
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
- The error of the value type if the value does not parse.
ValueErrorstates the text. ConfigError::InvalidFormatif the key is required and absent.
Sourcepub fn file_value<K: Key<G>>(&self) -> Result<Option<K::Value>, ConfigError>
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.
Sourcepub fn lookup<K: Key<G>>(&self) -> Result<Option<Lookup<K::Value>>, ConfigError>
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.
Sourcepub fn refuse_unknown_keys(&self) -> Result<(), ConfigError>
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'"
);