Skip to main content

cargo_util_config/
lib.rs

1//! Cargo's layered config system
2//!
3//! > This crate is maintained by the Cargo team, primarily for use by Cargo
4//! > and not intended for external use (except as a transitive dependency). This
5//! > crate may make major changes to its APIs or be deprecated without warning.
6//!
7//! [`ConfigLoader`] discovers and loads config files as [`ConfigStore`] layers.
8//! [`ConfigReader::get`] is the primary way to load [`schema`]s.
9//!
10//! # Example
11//!
12//! ```rust
13//! # fn main() -> anyhow::Result<()> {
14//! let shell = // ...
15//! # std::sync::Mutex::new(cargo_util_terminal::Shell::new());
16//! let current_dir = // ...
17//! # std::path::PathBuf::from("/nonexistent/project");
18//! let cargo_home = // ...
19//! # std::path::PathBuf::from("/nonexistent/cargo-home");
20//!
21//! let loader = cargo_util_config::ConfigLoader::new(&shell, &current_dir, &cargo_home);
22//! let layers = loader.load_layers(&current_dir)?;
23//! let config = cargo_util_config::ConfigStore::from_layers(layers)?;
24//! let env = // ...
25//! # cargo_util_config::Env::new();
26//!
27//! let reader = cargo_util_config::ConfigReader::new(&shell)
28//!   .config(&config)
29//!   .env(&env);
30//!
31//! use cargo_util_config::schema::CargoBuildConfig;
32//! let build_key = cargo_util_config::ConfigKey::from_parts(["build"]);
33//! let build = reader.get::<CargoBuildConfig>(build_key)?;
34//! # Ok(())
35//! # }
36//! ```
37
38mod config_store;
39mod config_value;
40mod de;
41mod definition;
42mod env;
43mod error;
44mod key;
45mod loader;
46mod reader;
47pub mod schema;
48mod value;
49
50pub use config_store::ConfigStore;
51pub use config_value::ConfigValue;
52pub use definition::{Definition, Origin, Scope};
53pub use env::Env;
54pub use error::ConfigError;
55pub use key::ConfigKey;
56pub use loader::ConfigLoader;
57pub use reader::{ConfigReader, expected};
58pub use value::{OptValue, Value};
59
60pub(crate) use config_value::is_nonmergeable_list;
61pub(crate) use key::ArrayItemKeyPath;
62
63const CRATES_IO_REGISTRY: &str = "crates-io";