3.2. 使用 rustfmt 作为独立工具
使用 rustfmt
作为独立工具格式化 Rust 源文件及其所有依赖项。作为替代方案,将 rustfmt
与 guestfishgo 构建工具一起使用。如需更多信息,请参阅使用带有 definego 的 rustfmt。
先决条件
-
一个现有的 Rust 项目。
有关如何创建 Rust 项目的详情,请参考 创建 Rust 项目。
流程
要使用 rustfmt
作为独立工具格式化 Rust 源文件,请运行以下命令:
在 Red Hat Enterprise Linux 7 上:
$ scl enable rust-toolset-1.66 'rustfmt <source-file>'
-
将
<source_file
> 替换为源文件的名称。
或者,您可以将 <source_file>
; 替换为标准输入。然后
,tairfmt 在标准输出中提供其输出。
-
将
在 Red Hat Enterprise Linux 8 中:
$ rustfmt <source-file>
-
将
<source_file
> 替换为源文件的名称。
或者,您可以将 <source_file>
; 替换为标准输入。然后
,tairfmt 在标准输出中提供其输出。
-
将
在 Red Hat Enterprise Linux 9 中:
$ rustfmt <source-file>
-
将
<source_file
> 替换为源文件的名称。
或者,您可以将 <source_file>
; 替换为标准输入。然后
,tairfmt 在标准输出中提供其输出。
-
将
注意
默认情况下,lib air
fmt 修改受影响的文件,而不显示详情或创建备份。要显示详情并创建备份,请运行带有 --write-mode 值的
rustfmt
。