Skip to content

Commit 141f74f

Browse files
committed
docs(source): doc comments for SourceConfigMap
1 parent 6e78631 commit 141f74f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/cargo/sources/config.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implementation of configuration for various sources
1+
//! Implementation of configuration for various sources.
22
//!
33
//! This module will parse the various `source.*` TOML configuration keys into a
44
//! structure usable by Cargo itself. Currently this is primarily used to map
@@ -14,11 +14,12 @@ use log::debug;
1414
use std::collections::{HashMap, HashSet};
1515
use url::Url;
1616

17+
/// Represents the entire `[source]` table in Cargo configuration.
1718
#[derive(Clone)]
1819
pub struct SourceConfigMap<'cfg> {
1920
/// Mapping of source name to the toml configuration.
2021
cfgs: HashMap<String, SourceConfig>,
21-
/// Mapping of `SourceId` to the source name.
22+
/// Mapping of [`SourceId`] to the source name.
2223
id2name: HashMap<SourceId, String>,
2324
config: &'cfg Config,
2425
}
@@ -67,6 +68,8 @@ struct SourceConfig {
6768
}
6869

6970
impl<'cfg> SourceConfigMap<'cfg> {
71+
/// Like [`SourceConfigMap::empty`] but includes sources from source
72+
/// replacement configurations.
7073
pub fn new(config: &'cfg Config) -> CargoResult<SourceConfigMap<'cfg>> {
7174
let mut base = SourceConfigMap::empty(config)?;
7275
let sources: Option<HashMap<String, SourceConfigDef>> = config.get("source")?;
@@ -78,6 +81,8 @@ impl<'cfg> SourceConfigMap<'cfg> {
7881
Ok(base)
7982
}
8083

84+
/// Creates the default set of sources that doesn't take `[source]`
85+
/// replacement into account.
8186
pub fn empty(config: &'cfg Config) -> CargoResult<SourceConfigMap<'cfg>> {
8287
let mut base = SourceConfigMap {
8388
cfgs: HashMap::new(),
@@ -112,11 +117,14 @@ impl<'cfg> SourceConfigMap<'cfg> {
112117
Ok(base)
113118
}
114119

120+
/// Returns the `Config` this source config map is associated with.
115121
pub fn config(&self) -> &'cfg Config {
116122
self.config
117123
}
118124

119-
/// Get the `Source` for a given `SourceId`.
125+
/// Gets the [`Source`] for a given [`SourceId`].
126+
///
127+
/// * `yanked_whitelist` --- Packages allowed to be used, even if they are yanked.
120128
pub fn load(
121129
&self,
122130
id: SourceId,
@@ -208,6 +216,7 @@ restore the source replacement configuration to continue the build
208216
Ok(Box::new(ReplacedSource::new(id, new_id, new_src)))
209217
}
210218

219+
/// Adds a source config with an associated name.
211220
fn add(&mut self, name: &str, cfg: SourceConfig) -> CargoResult<()> {
212221
if let Some(old_name) = self.id2name.insert(cfg.id, name.to_string()) {
213222
// The user is allowed to redefine the built-in crates-io
@@ -226,6 +235,7 @@ restore the source replacement configuration to continue the build
226235
Ok(())
227236
}
228237

238+
/// Adds a source config from TOML definition.
229239
fn add_config(&mut self, name: String, def: SourceConfigDef) -> CargoResult<()> {
230240
let mut srcs = Vec::new();
231241
if let Some(registry) = def.registry {

0 commit comments

Comments
 (0)