What is the point of rewriting imports so?

I ran the rust-fmt and it rewrote the following code:

use requests::{
    EmptyRequest,
    GenerateIntegersRequest,
    GenerateDecimalFractionsRequest,
    GenerateGaussiansRequest,
    GenerateStringsRequest,
    GenerateUUIDsRequest,
    GenerateBlobsRequest,
    RequestIntegers,
    RequestDecimalFractions,
    RequestGaussians,
    RequestStrings,
    RequestUUIDs,
    RequestBlobs,
};

to the following:

use requests::{EmptyRequest, GenerateBlobsRequest, GenerateDecimalFractionsRequest,
               GenerateGaussiansRequest, GenerateIntegersRequest, GenerateStringsRequest,
               GenerateUUIDsRequest};

I wonder, what is the reason of doing so? What do you think?

The first one is almost the same as prefixing all the entries. You don't usually read (only glance) the list of use so compact is good. Compiler will flag any unused.

1 Like

Well, what about this: if I wanna find that this module uses GenerateBlobsRequest, by looking at the second version I must read the whole 3 lines because the eye and the brain does not distinct visually one item from another; on contrary, if I look at the original version, the eye already sees the Generate part of each line and the reader is prepared to see only few consecutive lines and the user's brain performs kind of substr on shorter items.

Configuration has your back.

1 Like

It is interesting to me why the mixed was chosen as default style?

Formatting changes and defaults can be discussed through RFC PRs.
The repository for them holds a file, principles.md, which dictates the rationale behind the formatting guidelines.
In my opinion they went for minimizing vertical space as default because the use statement is part of the prelude of each file and programmers don't interact much with it in comparison to the actual Rust code. Effectively skipping the 'readability' and 'aesthetics' section.

Minimizing vertical space is part of the 'specifics' section which isn't highest priority, on top of that it contradicts with 'compatibility with version control practices'. I guess it's a given that these guidelines polarize Rust programmers, thank god we're allowed to customize per crate!

2 Likes