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
} else if let Some(registry_name) = args
.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"))
.map(Cow::Owned)
@ -157,7 +157,7 @@ pub fn install_crates(
.registries
.as_ref()
.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))
})?
.parse()

View file

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