pub struct Config(/* private fields */);Implementations§
Source§impl Config
impl Config
pub fn parse(text: &str) -> Result<Self, ConfigError>
pub fn get(&self, path: &str) -> Result<&Value, ConfigError>
Sourcepub fn f64(&self, path: &str) -> Result<f64, ConfigError>
pub fn f64(&self, path: &str) -> Result<f64, ConfigError>
A number. NaN and infinity are valid TOML and a value of no quantity, so they never pass; nor does a number beyond
1e15 or, but for zero, below 1e-15 in size (number).
Sourcepub fn non_negative(&self, path: &str) -> Result<f64, ConfigError>
pub fn non_negative(&self, path: &str) -> Result<f64, ConfigError>
A value that may be zero but not negative (dampings, frictions, a payload).
Sourcepub fn positive(&self, path: &str) -> Result<f64, ConfigError>
pub fn positive(&self, path: &str) -> Result<f64, ConfigError>
A value that must be strictly positive (masses, radii, stiffnesses, cycle times).
pub fn bool(&self, path: &str) -> Result<bool, ConfigError>
pub fn f64s(&self, path: &str) -> Result<Vec<f64>, ConfigError>
Sourcepub fn check_keys(
&self,
schema: &Config,
optional: &[&str],
) -> Result<(), ConfigError>
pub fn check_keys( &self, schema: &Config, optional: &[&str], ) -> Result<(), ConfigError>
Refuses a key that neither schema (a machine’s default config) nor optional has, so that a
misspelt key in a config file cannot pass silently. [bounds] is left out: it has its own check, and
so are the entries of arrays, which the code that reads them checks.
pub fn array(&self, path: &str) -> Result<&Vec<Value>, ConfigError>
Sourcepub fn set(&mut self, path: &str, value: Value) -> Result<(), ConfigError>
pub fn set(&mut self, path: &str, value: Value) -> Result<(), ConfigError>
Overwrites an existing value. New keys and type changes are rejected, so a typo cannot pass silently.
Sourcepub fn set_within(
&mut self,
path: &str,
value: Value,
schema: &Config,
optional: &[&str],
) -> Result<(), ConfigError>
pub fn set_within( &mut self, path: &str, value: Value, schema: &Config, optional: &[&str], ) -> Result<(), ConfigError>
set, and where the config has not got path, adds it where a file may have it (check_keys with the same
schema and optional takes it): in the type schema has there, or as given for a key of optional. A path of
neither is refused as by set (Missing), so a misspelt key still cannot pass silently.
Sourcepub fn set_text(&mut self, assignment: &str) -> Result<(), ConfigError>
pub fn set_text(&mut self, assignment: &str) -> Result<(), ConfigError>
Applies one path=value assignment, with the value in TOML syntax.
Sourcepub fn set_text_within(
&mut self,
assignment: &str,
schema: &Config,
optional: &[&str],
) -> Result<(), ConfigError>
pub fn set_text_within( &mut self, assignment: &str, schema: &Config, optional: &[&str], ) -> Result<(), ConfigError>
set_text as set_within adds a key.
Sourcepub fn to_text(&self) -> Result<String, ConfigError>
pub fn to_text(&self) -> Result<String, ConfigError>
The config as TOML text, which parse reads back to the same config. Comments are not kept.
Sourcepub fn hint(&self, error: &ConfigError) -> Option<ConfigHint>
pub fn hint(&self, error: &ConfigError) -> Option<ConfigHint>
Extra help for an error of this config, for a front end to append to its message (the error itself, its key and its detail stay as they are): for a path that is missing or unknown the nearest path the config has, where one is close (at most 2 edits, or a third of the path’s length); for a value out of range or of the wrong type the value the path has.
Sourcepub fn hint_within(
&self,
error: &ConfigError,
schema: &Config,
optional: &[&str],
) -> Option<ConfigHint>
pub fn hint_within( &self, error: &ConfigError, schema: &Config, optional: &[&str], ) -> Option<ConfigHint>
hint, with the paths set_within may add (schema’s and optional) among those a misspelt one is near.