loader

Finding, reading and merging the layered config files and GEST_ environment variables into Settings.

fn active_global_config_path

source

pub fn active_global_config_path() -> Option<PathBuf>

Return the active global config file path, if one exists on disk.

Parameter Type Description
returns Option<PathBuf> The path from $GEST_CONFIG or the XDG default, or None when no file is there or the path cannot be resolved.

fn active_project_config_paths

source

pub fn active_project_config_paths() -> Vec<PathBuf>

Return the active per-directory config file paths in load order, walking from filesystem root down to $CWD. Only files that exist on disk are included.

Parameter Type Description
returns Vec<PathBuf> The paths; empty when there are none.

fn load

source

pub fn load() -> Result<Settings, Error>

Load and merge configuration from all sources.

Resolution order (each layer overrides the previous):

  1. Global config: $GEST_CONFIG or $XDG_CONFIG_HOME/gest/config.toml
  2. Per-directory configs walking from filesystem root to $CWD, checking .config/gest.toml and .gest.toml at each level.
  3. Environment variables prefixed with GEST_ (e.g. GEST_STORAGE__DATA_DIR).
Parameter Type Description
returns Result<Settings, Error> The merged settings, or an error when a file cannot be read, holds invalid TOML or does not match Settings, or when the XDG config directory cannot be resolved.

fn global_config_path

source

fn global_config_path() -> Result<PathBuf, Error>

Resolve the path to the global config file, preferring $GEST_CONFIG over the XDG default.

Parameter Type Description
returns Result<PathBuf, Error> The path, which may not exist, or Error::XDGDirNotFound when $GEST_CONFIG is unset and the XDG config directory cannot be resolved.

fn merge_env

source

fn merge_env(base: &mut Table)

Merge environment variables prefixed with GEST_ into the config table.

__ separates nesting levels and key segments are lowercased. For example, GEST_STORAGE__DATA_DIR=foo becomes [storage] data_dir = "foo". GEST_CONFIG itself is skipped.

A value is inserted as a string when Settings accepts a string at that key, and otherwise as a bool, an integer or a float when it parses as one, so GEST_STORAGE__SYNC=false sets the bool storage.sync. A bool accepts the words that typed_env accepts, such as true, 1, yes and on, so the config value agrees with the variable read directly by super::storage::Settings::sync_enabled. A value that fits no type is inserted as a string, so loading reports the bad value. A variable that names a table, such as GEST_PAGER for [pager], or that nests under a key that is not a table, such as GEST_STORAGE__SYNC__X, is not a config key and is skipped.

Parameter Type Description
base &mut Table the merged table, changed in place

fn lookup

source

fn lookup<'a>(value: &'a Value, path: &[String]) -> Option<&'a Value>

Return the value at path inside value, if every segment exists.

Parameter Type Description
value &'a Value
path &[String]
returns Option<&'a Value>

fn lookup_table

source

fn lookup_table<'a>(table: &'a Table, path: &[String]) -> Option<&'a Value>

Return the value at the non-empty path inside table, if every segment exists.

Parameter Type Description
table &'a Table
path &[String]
returns Option<&'a Value>

fn typed_env_value

source

fn typed_env_value(path: &[String], raw: String) -> Value

Give a GEST_* value the type that Settings expects at path.

Parameter Type Description
path &[String]
raw String
returns Value A string when a string fits, else the first of bool, integer or float that the text parses as and that fits, else the string, so deserialization reports the mismatch.

const PROBING

source

const PROBING: LocalKey<std::cell::Cell<bool>>;

fn probing

source

pub(in crate::config) fn probing() -> bool

Whether this thread is probing a value with fits, so deserializers should not print warnings.

Parameter Type Description
returns bool

fn fits

source

fn fits(path: &[String], value: &Value) -> bool

Whether Settings deserializes from a table holding only value at path.

Deserializers print no warnings during the probe; the real load prints them once.

Parameter Type Description
path &[String]
value &Value
returns bool

fn merge_tables

source

fn merge_tables(base: &mut Table, overlay: Table)

Recursively merge overlay into base. Nested tables are merged; all other values are overwritten.

Parameter Type Description
base &mut Table the table to merge into, changed in place
overlay Table the table whose values win

fn read_toml

source

fn read_toml(path: &PathBuf) -> Result<Option<Table>, Error>

Read and parse a TOML file into a Table. Returns Ok(None) if the file does not exist.

Parameter Type Description
path &PathBuf the config file to read
returns Result<Option<Table>, Error> The parsed table, or an error when the file cannot be read or is invalid TOML.