00-rust安装
-1. rust介绍
Rust语法结构和C类语言类似,C类语音包括 C(面向过程型)/C++/C#(面向对象型)
0. 安装
不在本地安装,使用在线编译器(online compiler):Rust playground由rust官方提供
在IDE安装相关插件
如:VS Code
安装rust本地环境
在Mac OS
、 Linux
、windows的 WSL
中开发:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
如果想在 Windows 原生平台上开发 Rust 代码,首先需要确定安装 32 位的版本open in new window还是 64 位的版本open in new window。在安装过程中,它会询问你是想安装 GNU 工具链的版本还是 MSVC 工具链的版本。安装 GNU 工具链版本的话,不需要额外安装其他软件包。而安装 MSVC 工具链的话,需要先安装微软的 Visual Studioopen in new window 依赖。
以下为mac
安装示例
按1继续安装
其他Terminal指令
安装后做定期更新检查:
1. rustup update
(检查rust环境)
这个是一个win10
的示例

**信息内容 :rustc+版本号+(yyyy-mm-dd) **
2. rustc --version
(检查rustc, 本地编译的版本,适用于windows!!!)
和上面输出内容类似:
rustc 1.69.0 (84c898d65 2023-04-16)
好了,一切就绪后,我们可以来看看 src 下的 main.rs
里面的代码。
4. rustup self uninstall
(卸载)
__
rustup update
rustc --version #适用于windows!!!
rustc -V #适用于mac!!!
rustup self uninstall
5. 创建rust文件(零基础详见下)
cargo new --bin xxx(文件夹名)
6. rustc doc 编译文件
rustc xxx # 适用于mac!
7.执行文件
2. 创建一个工程
打开终端,输入:
cargo new --bin hello_world
显示:
Created binary (application) `hello_world` package
这样就创建好了一个新工程。这个新工程的目录组织结构是这样的:
hello_world
├── Cargo.toml
└── src
└── main.rs

我们从src
>>main.rs
查看项目内的代码(默认内容是"Hello,world"
)

fn main() {
println!("Hello, world!");
}
在新建的项目内打开Terminal,使用 cargo build
来编译。
$ cargo build
Compiling helloworld v0.1.0 (/home/mike/works/classes/helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 1.57s
使用 cargo run
命令可以直接运行程序。
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/helloworld`
Hello, world!
可以看到,最后终端打印出了 Hello, world。我们成功地执行了第一个 Rust 程序。