文章目录
一、Rust的编译器rustc
·查看版本
rustc-version
·编译生成二进制文件
rustc -o output filename filename.rs
·编译生成库文件
rustc --crate-type lib filename.rs
fn main()
{
println!("Hello, world!");
}
编译及运行
▶ rustc main.rs -o main
▶ ./main
Hello, world!
二、开发环境搭建
vscode
- rust-analyzer
- Error Lens(错误提示)
- Dependi:Cargo.toml crates版本管理
运行以下命令再Nightly Toolchain/Stable Toolchain去安装 Rust-Analyzer:
rustup component add rust-analyzer-preview
rustup 会将 rust-analyzer 安装到以下路径:
which rust-analyzer
/home/wangji/.cargo/bin/rust-analyzer
这样的好处是 rust-analyzer 会跟随rustup rustc 一起更新,也能在不同 rustc 版本的项目中用相应版本的rust-analyzer.
配置在vscode中
其他插件:
插件:rust-analyzer
会实时编译和分析你的 Rust 代码,提示代码中的错误,并对类型进行标注
插件的完整手册地址:https://rust-analyzer.github.io/manual.html。
插件: rust syntax
为代码提供语法高亮。
插件: crates
帮助你分析当前项目的依赖是否是最新的版本
插件: better toml
Rust 使用 toml 做项目的配置管理
插件: rust test lens
帮你快速运行某个 Rust 测试
插件:Tabnine
基于 AI 的自动补全,可以帮助你更快地撰写代码。
插件:GitHub Copilot
基于 AI 的自动补全,收费的100$/年,rust体验不佳(2023/05/05)
插件: Bookmarks
代码打标记,标记常用代码位置
代码保存自动格式化windows ctrl+shift+p
搜索open user set
添加如下json
{
"editor.formatOnSave"