gpt4 book ai didi

rust - 如何将 rustfmt 配置为发出制表符而不是这些缩进空格?

转载 作者:行者123 更新时间:2023-11-29 08:06:15 31 4
gpt4 key购买 nike

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

我有以下代码:

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

which rustfmt formats as (我用 ---> 替换了所有制表符,用 _ 替换了缩进空格以说明缩进 ):

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");
--->}
}

最佳答案

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

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

关于rust - 如何将 rustfmt 配置为发出制表符而不是这些缩进空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44224729/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com