Skip to content

Chains style and the await keyword #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Samuel-B-D opened this issue Oct 13, 2021 · 1 comment
Closed

Chains style and the await keyword #166

Samuel-B-D opened this issue Oct 13, 2021 · 1 comment

Comments

@Samuel-B-D
Copy link

Samuel-B-D commented Oct 13, 2021

I believe the style guideline about multi-line chains should be revised to not treat keyword the same way as it treat fields or methods.
I subjectively think that it is much more readable to keep the .await on the same line as it's associated future, and I think that the 2nd following snippet is much more readable:

#[tokio::main]
async fn main() -> reqwest::Result<()> {
    reqwest::Client::new()
        .get("http://example.org")
        .send()
        .await?
        .text()
        .await?;
    Ok(())
}
#[tokio::main]
async fn main() -> reqwest::Result<()> {
    reqwest::Client::new()
        .get("http://example.org")
        .send().await?
        .text().await?;
    Ok(())
}

This was initially requested as a configuration option to rust fmt here: rust-lang/rustfmt#4425
but I suspect that the guideline about multiline chain was made before the await keyword was adopted and that the official style guide should probably account for this.

@calebcartwright
Copy link
Member

Thanks for sharing your perspective, but I'm going to close. We're working on some things within rustfmt that'll give folks a bit more flexibility, including the ability to keep your awaits on the same line if you choose, but we aren't going to go about giving that flexibility by making a breaking change to the style specification as suggested here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants