pub struct ConfigFile { /* private fields */ }Expand description
A validated configuration file.
This structure contains the raw document tree.
§Examples
[[modules]]
path = "/some/pkcs11/libmod.so"
[[modules]]
path = "/other/pkcs11/libmod.so"Implementations§
Source§impl ConfigFile
impl ConfigFile
Sourcepub fn default_template(home: Option<&Home>) -> Result<Self>
pub fn default_template(home: Option<&Home>) -> Result<Self>
Returns the default configuration in template form.
All the configuration options with their defaults are commented out.
The configuration file from the specified home directory is not read; the home directory is just used to determine the location of the configuration file, which is embedded in the returned configuration file as a hint.
If home is None, no hint about the location of the
configuration file is embedded in the returned template.
Sourcepub fn file_name(home: &Home) -> PathBuf
pub fn file_name(home: &Home) -> PathBuf
Returns the absolute path of the config file for the specified home directory.
Sourcepub fn parse_default_home() -> Result<Self>
pub fn parse_default_home() -> Result<Self>
Reads and validates the configuration file from the default home directory.
If the configuration file does not exist, the default configuration file is returned. Any other error that occurs while reading the configuration is propagated to the caller.
Sourcepub fn parse_home(home: &Home) -> Result<Self>
pub fn parse_home(home: &Home) -> Result<Self>
Reads and validates the configuration file from the specified home directory.
If the configuration file does not exist, the default configuration file is returned. Any other error that occurs while reading the configuration is propagated to the caller.
Sourcepub fn parse_file(path: &Path) -> Result<Self>
pub fn parse_file(path: &Path) -> Result<Self>
Reads and validates the configuration file from the specified file.
The file must contain a valid toml document, which is consistent with the schema.
If the file does not exist, the default configuration file (as returned by is used. Any other error that occurs while reading the configuration is propagated to the caller.
Sourcepub fn parse_str(config: &str) -> Result<Self>
pub fn parse_str(config: &str) -> Result<Self>
Reads and validates the configuration.
The string must contain a valid toml document, which is consistent with the schema.
Sourcepub fn persist_to_home(&self, home: &Home) -> Result<()>
pub fn persist_to_home(&self, home: &Home) -> Result<()>
Writes the configuration to the home directory.
Sourcepub fn persist<P>(&self, path: P) -> Result<()>
pub fn persist<P>(&self, path: P) -> Result<()>
Writes the configuration to the specified file.
Sourcepub fn dump(&self, sink: &mut dyn Write) -> Result<()>
pub fn dump(&self, sink: &mut dyn Write) -> Result<()>
Writes the configuration to the given writer.
Sourcepub fn to_config(&self) -> Result<Config>
pub fn to_config(&self) -> Result<Config>
Return a Config based on the parsed configuration file.
This function is falliable, because a caller that modifies the
document returned by ConfigFile::as_item_mut may modify
the configuration to be invalid.
Sourcepub fn as_item_mut(&mut self) -> &mut Item
pub fn as_item_mut(&mut self) -> &mut Item
Returns the mutable document tree.
This allows the caller to modify the configuration file directly. As such, the resulting configuration may no longer be valid.