Rust学习第一天(helloworld,cargo)

该博客介绍了如何在中国地区一键安装Rust编程语言,包括使用curl命令和rustup初始化。当遇到crates.io更新受阻时,提出了切换到中科大镜像源的解决方案,详细说明了配置过程,并提供了使用git和HTTPS两种协议的地址。最终,通过重新编译项目确认问题已解决。
摘要由CSDN通过智能技术生成

一键安装rust
$ curl --proto ‘=https’ --tlsv1.2 -sSf https://sh.rustup.rs | sh
要想立即有rustc和cargo等等可执行
$ source ~/.cargo/env

包管理工具cargo
$ cargo new hello_world

$ cd hello_world
$ cargo build
发现卡住 update crates.io
原因:
天朝某神奇的GreatWall
解决办法:
使用中科大的rust源

cd ~/.cargo/
vi config
添加
[source.crates-io]
registry = “https://github.com/rust-lang/crates.io-index”
replace-with = ‘ustc’
[source.ustc]
registry = “git://mirrors.ustc.edu.cn/crates.io-index”

如果所处的环境中不允许使用 git 协议,可以把上面的地址改为
registry = “https://mirrors.ustc.edu.cn/crates.io-index”
输入:wq退出

重新
$ cd ~/hello_world
$ cargo build

编译通过!
$ cargo run
Compiling hello_world v0.1.0 (/Users/zhpan/rust/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 1.96s
Running target/debug/hello_world
Hello, world!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值