pub struct Form { /* private fields */ }Expand description
A configuration data structure that is kind-checked at runtime. Items are
declared using the item member function, after which their value can be
updated but their kind (bool, int, float, string) cannot change.
Implementations§
Source§impl Form
impl Form
Sourcepub fn item<T: Into<Value>>(self, key: &str, default: T, about: &str) -> Self
pub fn item<T: Into<Value>>(self, key: &str, default: T, about: &str) -> Self
Declares a new config item. Any item already declared with that name is replaced.
§Arguments
key- The name of the config itemdefault- The default valueabout- A description of the item for use in user reporting
Sourcepub fn merge_value_map_freezing(
self,
items: &HashMap<String, Value>,
to_freeze: &[&str],
) -> Result<Self, ConfigError>
pub fn merge_value_map_freezing( self, items: &HashMap<String, Value>, to_freeze: &[&str], ) -> Result<Self, ConfigError>
Merges in the contents of a string-value map, and freeze any of those items which are named in the given vector of keys to be frozen.
§Arguments
items- A map of values to update the map withto_freeze- A vector of keys to freeze, if the key is initems
Sourcepub fn merge_value_map(
self,
items: &HashMap<String, Value>,
) -> Result<Self, ConfigError>
pub fn merge_value_map( self, items: &HashMap<String, Value>, ) -> Result<Self, ConfigError>
Merges in the contents of a string-value map. The result is an error if any of the new keys have not already been declared in the form, or if they were declared as a different type.
§Arguments
items- A map of values to update the map with
Sourcepub fn merge_string_map(
self,
dict: &HashMap<String, String>,
) -> Result<Self, ConfigError>
pub fn merge_string_map( self, dict: &HashMap<String, String>, ) -> Result<Self, ConfigError>
Merges in the contents of a string-string map. The result is an error if any of the new keys have not already been declared in the form, or if any of the value strings do not parse to the declared type.
§Arguments
dict- A map of string to update the map with
Sourcepub fn merge_string_args<T: IntoIterator<Item = U>, U: Into<String>>(
self,
args: T,
) -> Result<Self, ConfigError>
pub fn merge_string_args<T: IntoIterator<Item = U>, U: Into<String>>( self, args: T, ) -> Result<Self, ConfigError>
Merges in a sequence of “key=value” pairs. The result is an error if any of the new keys have not already been declared in the form, or if any of the value strings do not parse to the declared type.
§Arguments
args- Iterator of string to update the map with
§Example
let form = base.merge_string_args(std::env::args().skip(1)).unwrap();pub fn merge_string_args_allowing_duplicates<T: IntoIterator<Item = U>, U: Into<String>>( self, args: T, ) -> Result<Self, ConfigError>
Sourcepub fn freeze(self, key: &str) -> Self
pub fn freeze(self, key: &str) -> Self
Freezes a parameter with the given name, if it exists, or otherwise panic.
Sourcepub fn value_map(&self) -> HashMap<String, Value>
pub fn value_map(&self) -> HashMap<String, Value>
Returns a hash map of the (key, value) items, stripping out the about messages. If the HDF5 feature is enabled, the result can be written directly to an HDF5 group via io::write_to_hdf5.
pub fn iter(&self) -> impl Iterator<Item = (&str, &Value)>
Sourcepub fn sorted_keys(&self) -> Vec<String>
pub fn sorted_keys(&self) -> Vec<String>
Returns a vector of the keys in this map, sorted alphabetically.