Rust Mac 使用国内源 (ustc) 之后依然无法下载最新包

目的及预期

目前在尝试Rust编程,根据教程进行尝试的时候被cargo下包卡住,不知道是否有人能指点下迷津?(是否某度出来的结果已经过时?现在已经不是这样配置了吗)

背景及环境

Mac: Catalina 10.15.4
Rust: 1.43.1
Cargo: 1.43.0
(rust这俩是github上官方推荐方法安装的)

配置

根据各种攻略所说,Cargo 添加以下配置就可以使用国内的源,如果不支持git协议则使用http地址,所以我添了以下配置(git和https的都试过了)

cat ~/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
#registry = "git://mirrors.ustc.edu.cn/crates.io-index"

手顺

follow 《Rust编程语言》里的guessing_game的demo(源地址

走到 cargo build或者cargo run的时候就一直会提示超时: (下面贴的是 【ran :0.7】我自己从0.3到0.7都试过一直这样)

guessing_game git:(master) ✗ cargo build
warning: spurious network error (2 tries remaining): [28] Timeout was reached (failed to download any data for `rand v0.7.3` within 30s)
warning: spurious network error (1 tries remaining): [28] Timeout was reached (failed to download any data for `rand v0.7.3` within 30s)
error: failed to download from `https://crates-io.proxy.ustclug.org/api/v1/crates/rand/0.7.3/download`

Caused by:
  [28] Timeout was reached (failed to download any data for `rand v0.7.3` within 30s)

然后我尝试ping了一下报错日志里提到的域名

ping crates-io.proxy.ustclug.org
PING crates-io.proxy.ustclug.org (127.233.233.233): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
^C
--- crates-io.proxy.ustclug.org ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss

但是直接访问配置中的域名是可以访问的,通过名字找包的方式也是可以找到rand包的

curl https://mirrors.ustc.edu.cn/crates.io-index/
curl https://mirrors.ustc.edu.cn/crates.io-index/                                                                     
<html>
<head><title>Index of /crates.io-index/</title></head>
<body>
<h1>Index of /crates.io-index/</h1><hr><pre><a href="../">../</a>
<a href="1/">1/</a>                                                 10-May-2020 02:47                   -
<a href="2/">2/</a>                                                 31-May-2020 20:45                   -
<a href="3/">3/</a>                                                 27-Dec-2016 16:11                   -
……省略一大堆

看起来是cargo组合同步域名规则改了或者ustcproxy域名映射换过了?对我来说直接翻源码有点难度…:sob:

其他添附文件

main.rs

extern crate rand;

use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    println!("Guess the number!");

    let secret_num = rand::thread_rng().gen_range(1, 101);

    println!("Please input your guess.");

    let mut guess = String::new();

    io::stdin().read_line(&mut guess)
        .ok()
        .expect("Failed to read line");

    let guess: u32 = guess.trim().parse()
        .expect("Not a number!");

    println!("You guessed: {}", guess);

    match guess.cmp(&secret_num) {
        Ordering::Less => println!("Too small!"),
        Ordering::Greater => println!("Too big!"),
        Ordering::Equal => println!("You win!"),
    }
}

Cargo.toml

[package]
name = "guessing_game"
version = "0.1.0"
authors = ["godlockin <chen.chen@aigauss.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand="0.7"
讨论数量: 2

中国科大的镜像不稳定,有单个ip的并发限制, 官方说添加 CARGO_HTTP_MULTIPLEXING=false 参考链接: mirrors.ustc.edu.cn/help/crates.io-...

3年前 评论

这个是说在使用nightly版本的时候可能会报错,我直接用的是官方的稳定版…不过似乎半夜是可以下载的,可能是和国内用户访问的频率流量有关

帮助原文⬇️

使用 nightly 版本时,Crates 源可能会出现 Couldn't resolve host name (Could not resolve host: crates) 错误(见 https://github.com/ustclug/discussions/issues/294)。一个临时的解决方法是在运行 cargo 的时候加入环境变量 CARGO_HTTP_MULTIPLEXING=false。
3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!