rust - rustfmt is not indenting method calls - Stack Overflow

admin2025-05-02  2

rustfmt is not indenting method calls by default in some cases.

Is there some configuration to make rustfmt indent the struct method call.

Default behavior:

fn foo() {
  query(
    r#"
    ...
    "#,
  )
  .bind()
  .execute()
  .await?;
  statement_start_unclear_visually();
}

Expected behavior:

fn foo() {
  query(
    r#"
    ...
    "#,
  )
    .bind()
    .execute()
    .await?;
  statement_start_clear_visually();
}

Note: This behavior happens when the expression for the struct is multiline. If struct expression query(...) is in one line then indentation behavior for method call is ok.

Rust Playground link.

转载请注明原文地址:http://www.anycun.com/QandA/1746124365a92012.html