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 基础语法 变量,基本类型,函数,注释和控制流,这些几乎是每种编程语言都具有的编程概念。