轻智能时代开启,谁在夯实智慧家庭的“地基”?
2026/6/24 4:00:26
Rust 开发依赖rustup(工具链管理器)、cargo(包管理器)和rustc(编译器),通过官方脚本一键安装。
下载安装脚本:
访问 https://www.rust-lang.org/tools/install,点击“Download rustup-init.exe (64-bit)”下载安装器(或直接运行命令):
# PowerShell 中执行(需管理员权限)Invoke-WebRequesthttps://win.rustup.rs/x86_64-OutFile rustup-init.exe运行安装器:
双击rustup-init.exe,按提示选择安装选项:
1) Proceed with installation (default),自动安装stable 工具链(最新稳定版)、cargo、rustc、rust-docs等;2) Customize installation,按需勾选(新手建议默认)。验证安装:
安装完成后,重启终端(PowerShell/CMD),执行以下命令验证:
rustc--version# 输出 rustc 版本(如 rustc 1.75.0 (82e1608df 2023-12-21))cargo--version# 输出 cargo 版本(如 cargo 1.75.0 (1d8b05cdd 2023-11-20))rustup--version# 输出 rustup 版本若官方源访问慢,可配置国内镜像(如中科大、清华源):
C:\Users\<用户名>\.cargo目录下创建config文件(无扩展名);[source.crates-io] replace-with = 'ustc' [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index" # 若 git 协议被墙,改用 https: # registry = "https://mirrors.ustc.edu.cn/crates.io-index" [net] git-fetch-with-cli = true # 使用系统 git 下载(避免 SSL 问题)通过rustup component add安装代码格式化、Lint 检查和调试工具:
# 代码格式化工具(类似 Prettier)rustup component add rustfmt# 代码检查工具(类似 ESLint)rustup component add clippy# 调试符号(用于 GDB/LLDB 调试)rustup component add llvm-tools-preview推荐IntelliJ IDEA Community Edition(免费开源,足够 Rust 开发),或Ultimate Edition(付费,含更多高级功能)。
IDEA 自带 JetBrains Runtime(JBR),无需额外安装 JDK。若需使用系统 JDK,确保版本 ≥11(推荐 JDK 17)。
IDEA 通过插件支持 Rust,需安装Rust 官方插件及辅助插件提升开发效率。
Ctrl+Alt+S);插件功能:
| 插件名称 | 功能 | 安装方式 |
|---|---|---|
| Toml | 编辑Cargo.toml时语法高亮、补全 | Marketplace 搜索 “Toml” 安装 |
| GitToolBox | 增强 Git 集成(显示行内提交信息、 blame) | Marketplace 搜索 “GitToolBox” 安装 |
| Rainbow Brackets | 彩色括号配对,提升代码可读性 | Marketplace 搜索 “Rainbow Brackets” 安装 |
| CodeGlance Pro | 右侧显示代码缩略图,快速跳转 | Marketplace 搜索 “CodeGlance Pro” 安装 |
| String Manipulation | 字符串转换(大小写、反转、编码等) | Marketplace 搜索 “String Manipulation” 安装 |
stable-x86_64-pc-windows-msvc或stable-x86_64-pc-windows-gnu,默认自动检测);hello-rust)和路径,点击Create。创建后生成标准 Cargo 项目结构:
hello-rust/ ├── .idea/ # IDEA 配置目录(自动生成) ├── src/ # 源代码目录 │ └── main.rs # 入口文件(Application 模板默认生成) ├── target/ # 构建输出目录(自动生成,含编译产物) ├── Cargo.toml # 项目配置(依赖、版本、构建脚本) └── Cargo.lock # 依赖版本锁定文件(自动生成)src/main.rs:fnmain(){println!("Hello, Rust! 🦀");}Hello, Rust! 🦀。Cargo.toml中添加:[package.metadata.rust-analyzer] debugger = ["gdb"] # 或 ["lldb"]Shift+F9),程序会在断点处暂停,可查看变量、调用栈。Ctrl+Alt+L),使用rustfmt自动格式化;clippy检查代码问题(如冗余代码、潜在 bug)。Cargo.toml添加依赖(如serde序列化库):[dependencies] serde = { version = "1.0", features = ["derive"] }cargo doc --open生成并打开项目文档(基于代码注释);安装cargo-profiler工具分析性能瓶颈:
cargo install cargo-profiler cargo profiler callgrind# 生成性能分析报告199.232.68.133 raw.githubusercontent.com);rustup-init.exe。launch.json中显式指定调试器路径(IDEA 会自动生成配置,无需手动修改)。Windows 下 Rust 开发环境的核心是rustup工具链+IntelliJ IDEA+Rust 插件。通过本文步骤,可快速搭建包含代码编辑、调试、格式化、依赖管理的完整环境。后续可根据需求扩展插件(如 Git 增强、UI 美化),进一步提升开发效率。
关键命令回顾:
rustup component add rustfmt clippy llvm-tools-previewcargo new hello-rustcargo runcargo build+ IDEA 调试器【开发语言】Rust语言介绍