当前位置:网站首页>Rust 入门指南(rustup, cargo)
Rust 入门指南(rustup, cargo)
2022-07-28 14:48:00 【InfoQ】
为什么使用 Rust ?
- Rust 网站的 Learn 部分(https://www.rust-lang.org/learn)
- Herbert Wolverson 的 Hands on Rust (https://hands-on-rust.com/)
安装 Rust
- rustup 是一个命令行工具,它可以作为编译器的工具链。
- cargo 是用于管理 projects、crates(rust 包)的命令行,并且是我们在处理 Rust 项目时最常使用的工具。
- 从 rust-lang.org 的 Getting Started 部分获取 Rust,
- 或者访问 rustup.rs 并按照安装说明进行操作,
- 最简单的方法是访问 GeekCode.cloud 使用云环境。
- 测试你的安装
$ rustup -v
- 检查更新
$ rustup check
- 更新你的安装
$ rustup update
Cargo — Rust 构建工具和包管理器
建立一个新项目
$ cargo new {project_name}- 创建一个新的 Hello World 程序,它使用默认项目结构、*main.rs* 文件和 Cargo.toml 项目文件。
- 默认情况下,这是一个二进制应用程序(如果我们需要开发 library / crate,添加
-lib 选项)。
- 默认情况下,Git 已初始化(可以使用其他开关自定义/禁用 )
- 最好坚持使用 _snake_case 来命名,因为这是 Rust 规范。
Cargo 基础知识
$ cargo check- 验证程序结构——这不会编译我们的程序,但会确保项目文件结构正确
$ cargo build- 在调试模式下构建应用程序
- 如果它不存在,这将在项目的根目录中创建一个 target 文件夹
- 添加 -release 切换到 release 模式构建(见下文)
$ cargo clean- 清理(即删除)构建文件,比如构建期间生成的任何二进制文件
$ cargo run- 运行程序 - 如果尚未构建,这也将构建应用程序
$ cargo test- 运行项目中存在的任何测试(默认脚手架中不会有任何测试)
Cargo
target
— Release vs Debug
cargo buildcargo run--release$ cargo [build|run] --release$ cargo build --release --target=wasm32-unknown-unknown--release代码格式化
$ cargo fmtClippy — 代码提示和建议
$ cargo clippy#![warn(clippy::all,clippy::pedantic)]
总结
边栏推荐
- MIT pointed out that the public pre training model should not be used indiscriminately
- 活动速递| Apache Doris 性能优化实战系列直播课程初公开,诚邀您来参加!
- 有道云笔记去除底部广告
- PyQt5快速开发与实战 5.1 表格与树
- Rxdart is used instead of stateful in fluent
- Common methods of qcustomplot drawing tools
- What are the process specifications of software testing? How to do it?
- PyQt5快速开发与实战 5.2 容器:装载更多的控件
- 知识点qwer
- 2. Self narration of open source GPS project hd-gr GNSS
猜你喜欢

What is the concept of game testing? What are the test methods and processes?

NTC,PT100热电阻转4-20mA温度信号转换器

Rongyun real-time community solution

Sharing of award-winning activities: you can get up to iphone13 after using WordPress to build your own blog

如何快速接入统一的认证鉴权体系
![[delete specified number leetcode]](/img/16/b40492d8414a363a3a24f00b4afd47.png)
[delete specified number leetcode]

Communication between client and server based on rsocket protocol

Docker implements redis cluster mode hash slot partition for 100 million level data storage

融云实时社区解决方案

活动速递| Apache Doris 性能优化实战系列直播课程初公开,诚邀您来参加!
随机推荐
An article about rsocket protocol
生命的感悟
Camera continuous shooting automatic test shell script
About how Simulink generates model coverage reports
如何快速接入统一的认证鉴权体系
Several slips of X rust, those things that have to be said
软件架构与设计(一)-----关键原则
5路DI/DO继电器输出远程IO采集模块Modbus TCP/IBF95
A wave of operation to solve the error problem of Laya scene editor
Software architecture and design (x) -- Architecture Technology
华为全球员工总数创新高:19.4万人,研发人员占比近50%
一次失败的破解经历
Rongyun real-time community solution
EasyExcel复杂表头导出(一对多)
Deutsche Telekom denied strengthening its cooperation with Huawei and said it had reduced its cooperation with Huawei in the past three years
PXE network installation
Software architecture and design (IX) -- component based architecture
The price war of off screen fingerprints has resumed, and second-line manufacturers are expected to win 30% of the market this year?
玩死原型链
What are the process specifications of software testing? How to do it?