Skip to main content

module_config_or_default

Function module_config_or_default 

Source
pub fn module_config_or_default<T: DeserializeOwned + Default>(
    provider: &dyn ConfigProvider,
    module_name: &str,
) -> Result<T, ConfigError>
Expand description

Lenient configuration loader that falls back to defaults.

This function provides forgiving behavior for modules that don’t require configuration:

  • If the module is not present in config → returns Ok(T::default())
  • If the module value is not an object → returns Ok(T::default())
  • If the module has no “config” field → returns Ok(T::default())
  • If “config” is present but invalid → returns Err(ConfigError::InvalidConfig)

Use this for modules that can operate with default configuration.

§Errors

Returns ConfigError::InvalidConfig if the config section exists but cannot be deserialized.