前言
本文耗时30秒
目录
一、安装Rust
- 下载安装VsCode Visual Sstudio Code
- 下载安装Rust编译工具 RUSTUP-INIT.EXE
- 执行下载的rustup-init ,按照菜鸟教程操作足以 安装
- VsCode中安装
rust-analyzer
、Native Debug
两个扩展插件 - 如果使用Mac电脑,curl下载,官方源安装速度会比较慢,可以修改成国内源
-
修改cargo文件夹下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"
-
carog 文件夹在哪里?
$CARGO_HOME/config.toml which defaults to: Windows: %USERPROFILE%.cargo (注: C:\Users\你的用户名\.cargo 新建config文件将上一点的源内容贴进去) Unix: $HOME/.cargo/config.toml
-
- Cargo 包社区 Cargo.io
rust -V
rustc 1.64.0 (a55dd71d5 2022-09-19)
二、Hello World
创建并运行项目
cargo new hello_world
cd hello_world
cargo build
cargo run
目录结构如下
先不用管为什么只有一个 main.rs
文件,以及其他文件的依赖,后续了解语法后,将单独选择一节说这个目录的含义和包管理(Cargo是rust官方的包管理工具,你可以想象成npm)。