Expand description
rattler_config is the shared configuration model of the rattler
ecosystem: the same config.toml keys are understood by pixi,
rattler-build, rattler-index and any other tool built on rattler.
§Extending the configuration
Tools plug their own keys into the shared model by defining an
extension struct and using it as the type parameter of
config::ConfigBase. Extension keys live at the top level of the same
TOML document, next to the shared keys:
use rattler_config::config::{Config, ConfigBase, MergeError};
use serde::{Deserialize, Serialize};
/// Keys that only make sense for *my* tool.
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct MyToolConfig {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub fancy_output: Option<bool>,
}
impl Config for MyToolConfig {
fn merge_config(self, other: &Self) -> Result<Self, MergeError> {
Ok(Self {
fancy_output: other.fancy_output.or(self.fancy_output),
})
}
// `validate` and `keys` have sensible defaults, override as needed.
fn keys(&self) -> Vec<String> {
vec!["fancy-output".to_string()]
}
}
pub type MyConfig = ConfigBase<MyToolConfig>;
let (config, unused_keys) = MyConfig::from_toml_str(
r#"
default-channels = ["conda-forge"]
fancy-output = true
definitely-a-typo = 1
"#,
)
.unwrap();
assert_eq!(config.default_channels.as_ref().map(Vec::len), Some(1));
assert_eq!(config.extensions.fancy_output, Some(true));
assert!(unused_keys.contains("definitely-a-typo"));Extensions must not use #[serde(deny_unknown_fields)]: every extension
is deserialized from the full configuration document and has to tolerate
the shared keys (and the keys of sibling tools).
§Loading
config::ConfigBase::load_from_files merges a list of files in order
(later files win) and validates the result.
config::ConfigBase::load_from_default_locations does the same for the
conventional locations described in locations, which is how tools
share one configuration: e.g. rattler-build can load
&["pixi", "rattler-build"] to layer its own configuration on top of
pixi’s.
§Editing
With the edit feature (enabled by default), config::ConfigBase::set
sets or unsets any key — including extension keys — by its dotted TOML
path, and config::ConfigBase::save writes the configuration back to
disk.
Re-exports§
pub use config::CommonConfig;pub use config::Config;pub use config::ConfigBase;pub use config::LoadError;pub use config::MergeError;pub use config::NoExtension;
Modules§
- config
- The shared configuration model for rattler-based tools.
- edit
- Editing support for
ConfigBase:set/unseta configuration value by its dotted TOML key path, and save the result back to disk. - locations
- Standard configuration file locations shared by rattler-based tools.