1
- //! Implementation of configuration for various sources
1
+ //! Implementation of configuration for various sources.
2
2
//!
3
3
//! This module will parse the various `source.*` TOML configuration keys into a
4
4
//! structure usable by Cargo itself. Currently this is primarily used to map
@@ -14,11 +14,12 @@ use log::debug;
14
14
use std:: collections:: { HashMap , HashSet } ;
15
15
use url:: Url ;
16
16
17
+ /// Represents the entire `[source]` table in Cargo configuration.
17
18
#[ derive( Clone ) ]
18
19
pub struct SourceConfigMap < ' cfg > {
19
20
/// Mapping of source name to the toml configuration.
20
21
cfgs : HashMap < String , SourceConfig > ,
21
- /// Mapping of `SourceId` to the source name.
22
+ /// Mapping of [ `SourceId`] to the source name.
22
23
id2name : HashMap < SourceId , String > ,
23
24
config : & ' cfg Config ,
24
25
}
@@ -67,6 +68,8 @@ struct SourceConfig {
67
68
}
68
69
69
70
impl < ' cfg > SourceConfigMap < ' cfg > {
71
+ /// Like [`SourceConfigMap::empty`] but includes sources from source
72
+ /// replacement configurations.
70
73
pub fn new ( config : & ' cfg Config ) -> CargoResult < SourceConfigMap < ' cfg > > {
71
74
let mut base = SourceConfigMap :: empty ( config) ?;
72
75
let sources: Option < HashMap < String , SourceConfigDef > > = config. get ( "source" ) ?;
@@ -78,6 +81,8 @@ impl<'cfg> SourceConfigMap<'cfg> {
78
81
Ok ( base)
79
82
}
80
83
84
+ /// Creates the default set of sources that doesn't take `[source]`
85
+ /// replacement into account.
81
86
pub fn empty ( config : & ' cfg Config ) -> CargoResult < SourceConfigMap < ' cfg > > {
82
87
let mut base = SourceConfigMap {
83
88
cfgs : HashMap :: new ( ) ,
@@ -112,11 +117,14 @@ impl<'cfg> SourceConfigMap<'cfg> {
112
117
Ok ( base)
113
118
}
114
119
120
+ /// Returns the `Config` this source config map is associated with.
115
121
pub fn config ( & self ) -> & ' cfg Config {
116
122
self . config
117
123
}
118
124
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.
120
128
pub fn load (
121
129
& self ,
122
130
id : SourceId ,
@@ -208,6 +216,7 @@ restore the source replacement configuration to continue the build
208
216
Ok ( Box :: new ( ReplacedSource :: new ( id, new_id, new_src) ) )
209
217
}
210
218
219
+ /// Adds a source config with an associated name.
211
220
fn add ( & mut self , name : & str , cfg : SourceConfig ) -> CargoResult < ( ) > {
212
221
if let Some ( old_name) = self . id2name . insert ( cfg. id , name. to_string ( ) ) {
213
222
// The user is allowed to redefine the built-in crates-io
@@ -226,6 +235,7 @@ restore the source replacement configuration to continue the build
226
235
Ok ( ( ) )
227
236
}
228
237
238
+ /// Adds a source config from TOML definition.
229
239
fn add_config ( & mut self , name : String , def : SourceConfigDef ) -> CargoResult < ( ) > {
230
240
let mut srcs = Vec :: new ( ) ;
231
241
if let Some ( registry) = def. registry {
0 commit comments