一、cargo
1、cargo
比较大的项目就不适合用rustc进行编译了,此时就需要使用cargo
在安装包的时候,会遇到网速慢卡住的问题,这时候就要更换国内源或者设置代理
-
方法一:设置命令行代理
-
方法二:换源
进入用户目录下的 .cargo 文件夹(~/.cargo),新建一个名为 config 的文件,在 windows 系统中需注意后缀名为空。在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”
2.通用的编程概念
变量与可变性
fn main() {
let x = 5;
let x = x + 1;
let x = x * 2;
println!("{}",x);
let space = " ";
let space = space.len();
// let mut space = " ";
// space = space.len();
}
https://kaisery.github.io/trpl-zh-cn/ch01-01-installation.html