Skip to main content

Config

Struct Config 

Source
pub struct Config(/* private fields */);

Implementations§

Source§

impl Config

Source

pub fn parse(text: &str) -> Result<Self, ConfigError>

Source

pub fn get(&self, path: &str) -> Result<&Value, ConfigError>

Source

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).

Source

pub fn non_negative(&self, path: &str) -> Result<f64, ConfigError>

A value that may be zero but not negative (dampings, frictions, a payload).

Source

pub fn positive(&self, path: &str) -> Result<f64, ConfigError>

A value that must be strictly positive (masses, radii, stiffnesses, cycle times).

Source

pub fn bool(&self, path: &str) -> Result<bool, ConfigError>

Source

pub fn f64s(&self, path: &str) -> Result<Vec<f64>, ConfigError>

Source

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.

Source

pub fn array(&self, path: &str) -> Result<&Vec<Value>, ConfigError>

Source

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.

Source

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.

Source

pub fn set_text(&mut self, assignment: &str) -> Result<(), ConfigError>

Applies one path=value assignment, with the value in TOML syntax.

Source

pub fn set_text_within( &mut self, assignment: &str, schema: &Config, optional: &[&str], ) -> Result<(), ConfigError>

set_text as set_within adds a key.

Source

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.

Source

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.

Source

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.

Source

pub fn leaves(&self) -> Vec<(String, Value)>

Every scalar value with its dotted path, for the parameter panel and the translation check.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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 Debug for Config

Source§

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

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

impl PartialEq for Config

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Config

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.