File tree 2 files changed +26
-10
lines changed
2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,36 @@ impl<'de> serde::de::Deserialize<'de> for RustdocExternMode {
52
52
}
53
53
}
54
54
55
- #[ derive( serde:: Deserialize , Debug , Default ) ]
55
+ #[ derive( serde:: Deserialize , Debug ) ]
56
56
#[ serde( default ) ]
57
57
pub struct RustdocExternMap {
58
+ #[ serde( deserialize_with = "default_crates_io_to_docs_rs" ) ]
58
59
pub ( crate ) registries : HashMap < String , String > ,
59
60
std : Option < RustdocExternMode > ,
60
61
}
61
62
63
+ impl Default for RustdocExternMap {
64
+ fn default ( ) -> Self {
65
+ let mut registries = HashMap :: new ( ) ;
66
+ registries. insert ( "crates-io" . into ( ) , "https://docs.rs/" . into ( ) ) ;
67
+ Self {
68
+ registries,
69
+ std : None ,
70
+ }
71
+ }
72
+ }
73
+
74
+ fn default_crates_io_to_docs_rs < ' de , D : serde:: Deserializer < ' de > > (
75
+ de : D ,
76
+ ) -> Result < HashMap < String , String > , D :: Error > {
77
+ use serde:: Deserialize ;
78
+ let mut registries = HashMap :: deserialize ( de) ?;
79
+ if !registries. contains_key ( "crates-io" ) {
80
+ registries. insert ( "crates-io" . into ( ) , "https://docs.rs/" . into ( ) ) ;
81
+ }
82
+ Ok ( registries)
83
+ }
84
+
62
85
impl hash:: Hash for RustdocExternMap {
63
86
fn hash < H : hash:: Hasher > ( & self , into : & mut H ) {
64
87
self . std . hash ( into) ;
Original file line number Diff line number Diff line change @@ -1217,15 +1217,8 @@ impl Config {
1217
1217
// Note: This does not support environment variables. The `Unit`
1218
1218
// fundamentally does not have access to the registry name, so there is
1219
1219
// nothing to query. Plumbing the name into SourceId is quite challenging.
1220
- self . doc_extern_map . try_borrow_with ( || {
1221
- let mut extern_map = self . get :: < RustdocExternMap > ( "doc.extern-map" ) ;
1222
- if let Ok ( map) = & mut extern_map {
1223
- map. registries
1224
- . entry ( "crates-io" . into ( ) )
1225
- . or_insert ( "https://docs.rs/" . into ( ) ) ;
1226
- }
1227
- extern_map
1228
- } )
1220
+ self . doc_extern_map
1221
+ . try_borrow_with ( || self . get :: < RustdocExternMap > ( "doc.extern-map" ) )
1229
1222
}
1230
1223
1231
1224
/// Returns the `[target]` table definition for the given target triple.
You can’t perform that action at this time.
0 commit comments