From 69a8e96711f2731ffde46e4d0712a627d4b875a8 Mon Sep 17 00:00:00 2001 From: wenyongda Date: Wed, 26 Mar 2025 23:37:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_posts/Rust.md | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/source/_posts/Rust.md b/source/_posts/Rust.md index 383d521..81eb04b 100644 --- a/source/_posts/Rust.md +++ b/source/_posts/Rust.md @@ -224,6 +224,62 @@ fn main() { {} ``` +# Rust 格式化代码 + +## rustfmt + +只会格式化单个Rust文件 + +```shell +rustfmt main.rs +``` + +## cargo fmt + +会格式化整个Rust项目 + +```shell +cargo fmt +``` + +# Rust 构建 + +基于cargo 创建的整个项目进行构建 + +```shell +cargo build +# 简写 +cargo b +``` + +默认按照Debug模式进行构建 + +若进行Release模式构建 + +```shell +cargo build --release +cargo b --release +``` + +# Rust 运行 + +默认先按照Debug模式进行构建,然后再执行可执行文件 + +```shell +cargo run +# 简写 +cargo r +``` + +想只输出实际内容 + +```shell +cargo run --quiet +cargo r --quiet +``` + + + # Rust 基础语法 变量,基本类型,函数,注释和控制流,这些几乎是每种编程语言都具有的编程概念。