如何配置rustfmt来发出标签而不是这些缩进空格?

时间:2017-05-28 07:11:32

标签: rust

为什么rustfmt会在下面的代码示例中发出缩进空格,以及如何将其配置为停止?

我有以下代码:

fn main() {
    if {
        let to_comp = true;
        if to_comp { true } else { false }
    } {
        println!("true");
    }
}

哪个rustfmt格式为(我已用--->替换所有标签,而缩进空格用_来说明缩进):

fn main() {
--->if {
--->--->___let to_comp = true;
--->--->___if to_comp { true } else { false }
--->--->__} {
--->--->println!("true");
--->}
}

我的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"

我想知道是否存在rustfmt配置选项,它只会发出缩进选项卡。所以代码的格式如下:

fn main() {
--->if {
--->--->let to_comp = true;
--->--->if to_comp { true } else { false }
--->--->} {
--->--->println!("true");
--->}
}

1 个答案:

答案 0 :(得分:3)

您可以尝试control_style = "Rfc"。输出将如下所示:

fn main() {
    if {
        let to_comp = true;
        if to_comp { true } else { false }
    }
    {
        println!("true");
    }
}