pub struct LoadOptions { /* private fields */ }Expand description
Limits and include policy for loading configuration.
Build with LoadOptions::new (the safe defaults) and the builder
methods, then pass to Config::from_file_with,
Config::from_string_with,
ConfigBuilder::load_options or
HotReloadConfig::from_file_with.
§Examples
use config_lib::{Config, LoadOptions};
// Strict NOML for a file: no include, no env()
let options = LoadOptions::new().strict(true);
let config = Config::from_string_with("port = 8080", Some("conf"), &options)?;
assert_eq!(config.get_or("port", 0u16), 8080);Implementations§
Source§impl LoadOptions
impl LoadOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
The default options (see the module documentation).
Sourcepub fn strict_defaults() -> Self
pub fn strict_defaults() -> Self
Strict options: the defaults with LoadOptions::strict set.
Sourcepub fn strict(self, strict: bool) -> Self
pub fn strict(self, strict: bool) -> Self
Read NOML strictly: include and every function call (env()
included) are refused with Error::Parse. Other formats read only
their own text either way.
Sourcepub fn allow_include_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn allow_include_dir(self, dir: impl Into<PathBuf>) -> Self
Also allow NOML includes of files inside dir (and its
subdirectories). The directory of the file being loaded is always
allowed. The check is made on the canonical path, so .. and
symbolic links cannot leave the allowed directories.
Sourcepub fn allow_includes_anywhere(self) -> Self
pub fn allow_includes_anywhere(self) -> Self
Allow NOML includes of any regular file the process can read. Not recommended for files other users can write.
Sourcepub fn max_file_size(self, bytes: u64) -> Self
pub fn max_file_size(self, bytes: u64) -> Self
Largest file read, in bytes, for the configuration file and each
included file. Default DEFAULT_MAX_FILE_SIZE.
Sourcepub fn max_includes(self, count: usize) -> Self
pub fn max_includes(self, count: usize) -> Self
Largest number of included files, over all levels. Default
DEFAULT_MAX_INCLUDES.
Sourcepub fn max_expanded_size(self, bytes: u64) -> Self
pub fn max_expanded_size(self, bytes: u64) -> Self
Largest size, in bytes, a NOML document may expand to through
${...} references. Default DEFAULT_MAX_EXPANDED_SIZE. The size
is an estimate that counts a small overhead for every value, so it
is somewhat larger than the text of the values.
Sourcepub fn max_expansions(self, count: usize) -> Self
pub fn max_expansions(self, count: usize) -> Self
Largest number of ${...} references in a NOML document, included
files counted. Default DEFAULT_MAX_EXPANSIONS.
Sourcepub fn max_expansion_depth(self, depth: usize) -> Self
pub fn max_expansion_depth(self, depth: usize) -> Self
Longest chain of ${...} references. Default
DEFAULT_MAX_EXPANSION_DEPTH.