rust - 如何将 rustfmt 配置为不为匹配的不安全 block 模式发出对齐空格?

标签 rust rust-cargo

我的 rustfmt 配置当前将以下代码格式化为具有对齐空格,如下所示。在以下代码中,我用 . 替换了空格,用 ---> 替换了制表符。

fn main() {
--->match unsafe {
--->--->......0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
--->--->.....} {
--->--->0 => println!("0"),
--->--->_ => println!("not 0 or 1"),
--->}
}

生成上述代码示例的rustfmt 配置(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"
control_style = "Rfc"
match_style = "Rfc"
unsafe_style = "Rfc"
where_layout = "Horizontal"
where_pred_indent = "Block"
where_style = "Rfc"

如何将 rustfmt 配置为不为先前的代码发出对齐空格(标记为:.),以便 rustfmt 仅缩进带有类似以下代码的选项卡?

fn main() {
--->match unsafe {
--->--->0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
--->--->} {
--->--->0 => println!("0"),
--->--->_ => println!("not 0 or 1"),
--->}
}

最佳答案

这是一个错误。我创建了一个 PR解决这个问题,所以在它合并后,rustfmt 将不会在您的配置中发出空格。

关于rust - 如何将 rustfmt 配置为不为匹配的不安全 block 模式发出对齐空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44364221/

相关文章:

rust - 如何导入同一个 crate 的多个版本?

generics - 如何将Rust函数类型中的特征放入数组类型中?

rust - 你如何在 Rust 中使用父模块导入?

asynchronous - tokio async rust 上的 Yield 是什么意思?

rust - Box::into_raw() 和 Box::leak() 到底有什么区别?

rust - native 库 `kernel32` 被多个包链接

rust - "the trait is not implemented for Self"尽管它完全是

rust - 如何发布测试版的 crate 以进行有限的公开测试?

rust - 外部库作为对本地库的依赖

rust - 无法编译 stb_truetype 0.2.4 因为 "slice pattern syntax is experimental"