为什么 rustfmt 在下面的代码示例中发出缩进空格,以及如何将其配置为停止?
我有以下代码:
fn main() {
if {
let to_comp = true;
if to_comp { true } else { false }
} {
println!("true");
}
}
Run Code Online (Sandbox Code Playgroud)
rustfmt 格式为(我已替换所有制表符--->和缩进空格以_说明缩进):
fn main() {
--->if {
--->--->___let to_comp = true;
--->--->___if to_comp { true } else { false }
--->--->__} {
--->--->println!("true");
--->}
}
Run Code Online (Sandbox Code Playgroud)
我rustfmt.toml的上述代码:
tab_spaces = 4
hard_tabs = true
array_layout = "Block"
reorder_imports = true
newline_style = "Unix"
spaces_within_angle_brackets = false
spaces_within_parens = false
spaces_within_square_brackets = false
fn_args_layout = "Block"
fn_call_style = "Block"
fn_return_indent = "WithArgs"
fn_brace_style = "SameLineWhere"
generics_indent= "Block"
item_brace_style = "PreferSameLine"
where_layout = "Horizontal"
where_pred_indent = "Block"
where_style = "Rfc"
Run Code Online (Sandbox Code Playgroud)
我想知道是否存在一个rustfmt仅发出用于缩进的选项卡的配置选项。所以代码的格式如下:
fn main() {
--->if {
--->--->let to_comp = true;
--->--->if to_comp { true } else { false }
--->--->} {
--->--->println!("true");
--->}
}
Run Code Online (Sandbox Code Playgroud)
你可以试试control_style = "Rfc"。输出将如下所示:
fn main() {
if {
let to_comp = true;
if to_comp { true } else { false }
}
{
println!("true");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4504 次 |
| 最近记录: |