Skip to content

Commit f917444

Browse files
committed
docs(gctx): talk about two-layer of deserialization
1 parent 54a6497 commit f917444

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/cargo/util/context/mod.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
//! - [`StringList`]: Get a value that is either a list or a whitespace split
2121
//! string.
2222
//!
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+
//!
2339
//! ## Map key recommendations
2440
//!
2541
//! Handling tables that have arbitrary keys can be tricky, particularly if it
@@ -40,14 +56,6 @@
4056
//! structs/maps, but if it is a struct or map, then it will not be able to
4157
//! read the environment variable due to ambiguity. (See `ConfigMapAccess` for
4258
//! 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.
5159
5260
use crate::util::cache_lock::{CacheLock, CacheLockMode, CacheLocker};
5361
use std::borrow::Cow;
@@ -2157,6 +2165,7 @@ enum KeyOrIdx {
21572165
Idx(usize),
21582166
}
21592167

2168+
/// Similar to [`toml::Value`] but includes the source location where it is defined.
21602169
#[derive(Eq, PartialEq, Clone)]
21612170
pub enum ConfigValue {
21622171
Integer(i64, Definition),

0 commit comments

Comments
 (0)