|
20 | 20 | //! - [`StringList`]: Get a value that is either a list or a whitespace split |
21 | 21 | //! string. |
22 | 22 | //! |
| 23 | +//! ## Config deserialization |
| 24 | +//! |
| 25 | +//! Cargo uses a two-layer deserialization approach: |
| 26 | +//! |
| 27 | +//! 1. **External sources → `ConfigValue`** --- |
| 28 | +//! Configuration files, environment variables, and CLI `--config` arguments |
| 29 | +//! are parsed into [`ConfigValue`] instances via [`ConfigValue::from_toml`]. |
| 30 | +//! These parsed results are stored in [`GlobalContext`]. |
| 31 | +//! |
| 32 | +//! 2. **`ConfigValue` → Target types** --- |
| 33 | +//! The [`GlobalContext::get`] method uses a [custom serde deserializer](Deserializer) |
| 34 | +//! to convert [`ConfigValue`] instances to the caller's desired type. |
| 35 | +//! Precedence between [`ConfigValue`] sources is resolved during retrieval |
| 36 | +//! based on [`Definition`] priority. |
| 37 | +//! See the top-level documentation of the [`de`] module for more. |
| 38 | +//! |
23 | 39 | //! ## Map key recommendations |
24 | 40 | //! |
25 | 41 | //! Handling tables that have arbitrary keys can be tricky, particularly if it |
|
40 | 56 | //! structs/maps, but if it is a struct or map, then it will not be able to |
41 | 57 | //! read the environment variable due to ambiguity. (See `ConfigMapAccess` for |
42 | 58 | //! more details.) |
43 | | -//! |
44 | | -//! ## Internal API |
45 | | -//! |
46 | | -//! Internally config values are stored with the [`ConfigValue`] type after they |
47 | | -//! have been loaded from disk. This is similar to the `toml::Value` type, but |
48 | | -//! includes the definition location. The `get()` method uses serde to |
49 | | -//! translate from [`ConfigValue`] and environment variables to the caller's |
50 | | -//! desired type. |
51 | 59 |
|
52 | 60 | use crate::util::cache_lock::{CacheLock, CacheLockMode, CacheLocker}; |
53 | 61 | use std::borrow::Cow; |
@@ -2157,6 +2165,7 @@ enum KeyOrIdx { |
2157 | 2165 | Idx(usize), |
2158 | 2166 | } |
2159 | 2167 |
|
| 2168 | +/// Similar to [`toml::Value`] but includes the source location where it is defined. |
2160 | 2169 | #[derive(Eq, PartialEq, Clone)] |
2161 | 2170 | pub enum ConfigValue { |
2162 | 2171 | Integer(i64, Definition), |
|
0 commit comments