Skip to main content

LoadOptions

Struct LoadOptions 

Source
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

Source

pub fn new() -> Self

The default options (see the module documentation).

Source

pub fn strict_defaults() -> Self

Strict options: the defaults with LoadOptions::strict set.

Source

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.

Source

pub fn is_strict(&self) -> bool

Whether NOML is read strictly.

Source

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.

Source

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.

Source

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.

Source

pub fn max_includes(self, count: usize) -> Self

Largest number of included files, over all levels. Default DEFAULT_MAX_INCLUDES.

Source

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.

Source

pub fn max_expansions(self, count: usize) -> Self

Largest number of ${...} references in a NOML document, included files counted. Default DEFAULT_MAX_EXPANSIONS.

Source

pub fn max_expansion_depth(self, depth: usize) -> Self

Longest chain of ${...} references. Default DEFAULT_MAX_EXPANSION_DEPTH.

Trait Implementations§

Source§

impl Clone for LoadOptions

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 LoadOptions

Source§

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

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

impl Default for LoadOptions

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> 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 = !

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.