rustfmt多行结构体表达式下方法调用未缩进,求配置方案
rustfmt多行结构体表达式链式调用缩进配置
rustfmt默认在结构体表达式(如query(...))为多行时,不会对后续的链式方法调用进行缩进,单行场景下缩进行为正常:
默认行为代码:
fn foo() { query( r#" ... "#, ) .bind() .execute() .await?; statement_start_unclear_visually(); }
期望的缩进效果:
fn foo() { query( r#" ... "#, ) .bind() .execute() .await?; statement_start_clear_visually(); }
可以通过rustfmt的配置项实现这个需求:在你的rustfmt.toml配置文件中添加以下设置:
chain_indent = "block"
chain_indent配置用于控制链式调用的缩进规则,"block"选项会让链式调用相对于起始表达式的块层级进行缩进,正好解决多行结构体表达式后方法调用无缩进的问题。
内容的提问来源于stack exchange,提问作者Ravi Upadhyay
相关产品推荐
相关产品推荐

