Fix loading .cargo/config.toml (#1217)

Fixed #1216

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-07-19 12:15:57 +10:00 committed by GitHub
parent 07bc44e059
commit 47f79a9660
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -148,7 +148,7 @@ pub fn install_crates(
index index
} else if let Some(registry_name) = args } else if let Some(registry_name) = args
.registry .registry
.or_else(|| config.registry.map(|registry| registry.default)) .or_else(|| config.registry.and_then(|registry| registry.default))
{ {
env::var(format!("CARGO_REGISTRIES_{registry_name}_INDEX")) env::var(format!("CARGO_REGISTRIES_{registry_name}_INDEX"))
.map(Cow::Owned) .map(Cow::Owned)
@ -157,7 +157,7 @@ pub fn install_crates(
.registries .registries
.as_ref() .as_ref()
.and_then(|registries| registries.get(&registry_name)) .and_then(|registries| registries.get(&registry_name))
.map(|registry| Cow::Borrowed(registry.index.as_str())) .and_then(|registry| registry.index.as_deref().map(Cow::Borrowed))
.ok_or_else(|| BinstallError::UnknownRegistryName(registry_name)) .ok_or_else(|| BinstallError::UnknownRegistryName(registry_name))
})? })?
.parse() .parse()

View file

@ -52,12 +52,12 @@ pub enum Env {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Registry { pub struct Registry {
pub index: CompactString, pub index: Option<CompactString>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct DefaultRegistry { pub struct DefaultRegistry {
pub default: CompactString, pub default: Option<CompactString>,
} }
#[derive(Debug, Default, Deserialize)] #[derive(Debug, Default, Deserialize)]