Skip to main content

ConfigFile

Struct ConfigFile 

Source
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

Source

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.

Source

pub fn file_name(home: &Home) -> PathBuf

Returns the absolute path of the config file for the specified home directory.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn persist_to_home(&self, home: &Home) -> Result<()>

Writes the configuration to the home directory.

Source

pub fn persist<P>(&self, path: P) -> Result<()>
where P: AsRef<Path>,

Writes the configuration to the specified file.

Source

pub fn dump(&self, sink: &mut dyn Write) -> Result<()>

Writes the configuration to the given writer.

Source

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.

Source

pub fn as_item(&self) -> &Item

Returns the document tree.

Source

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.

Trait Implementations§

Source§

impl Clone for ConfigFile

Source§

fn clone(&self) -> Self

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 ConfigFile

Source§

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

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

impl Default for ConfigFile

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.