Skip to main content

Config

Struct Config 

Source
pub struct Config<Cfg> { /* private fields */ }
Expand description

Builder that collects configuration Sources and merges them.

Config<Cfg> is generic over a target configuration type Cfg. When Cfg implements serde::Deserialize and Combine, Config can deserialize the merged configuration into the typed value using extract().

Implementations§

Source§

impl<Cfg> Config<Cfg>

Source

pub fn new() -> Self

Source

pub fn with_source(self, source: impl Source + 'static) -> Self

Source

pub fn with_sources<I, S>(self, sources: I) -> Self
where S: Source + 'static, I: IntoIterator<Item = S>,

Source

pub fn set_value<Fmt>( &self, path: &str, value: impl Into<Value>, in_config_path: impl AsRef<Path>, ) -> Result<(), WriteError>
where Fmt: 'static + Format,

Sets the value under specified path creating new or merging it into existing config file

Source

pub fn unset_value<Fmt>( &self, path: &str, in_config_path: &Path, ) -> Result<Option<Value>, WriteError>
where Fmt: Format,

Source§

impl<Cfg: DeserializeOwned + JsonSchema + Combine + Validate> Config<Cfg>

Source

pub fn with_deprecation_clb( self, clb: impl Fn(&[&str], Option<&str>, Option<&str>) + 'static, ) -> Self

Provide a callback used to report use of deprecated fields. The callback will receive full path of the property and an optional deprecation reason.

Source

pub fn extract(&self) -> Result<Cfg, ReadError>

Deserializes the marged config into the config type and performs deprecation checks and validation.

Source

pub fn data(&self, with_defaults: bool) -> Result<Value, ReadError>

Returns raw merged data

Source

pub fn get_value( &self, path: &str, with_defaults: bool, ) -> Result<Option<Value>, ReadError>

Returns value under specified path

Source

pub fn json_schema(&self) -> Schema

Returns JSON Schema describing the config type

Source

pub fn markdown(&self) -> String

Returns Markdown describing the config type

Source

pub fn complete_path(&self, prefix: &str) -> Vec<String>

Given a prefix like some.va would return possible completions, e.g. some.value and some.validator

Trait Implementations§

Source§

impl<Cfg> Default for Config<Cfg>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Cfg> Freeze for Config<Cfg>

§

impl<Cfg> !RefUnwindSafe for Config<Cfg>

§

impl<Cfg> !Send for Config<Cfg>

§

impl<Cfg> !Sync for Config<Cfg>

§

impl<Cfg> Unpin for Config<Cfg>
where Cfg: Unpin,

§

impl<Cfg> UnsafeUnpin for Config<Cfg>

§

impl<Cfg> !UnwindSafe for Config<Cfg>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.