Skip to content

Feature request: Option to have one "use" statement per file #5360

Open
@CrendKing

Description

@CrendKing

Currently imports_granularity = 'One' merges all imports into one "use" statement. In my opinion, functionally it does two separate things: 1) Combine all "use" statements; 2) apply imports_granularity = 'Crate' inside the braces. Obviously it has the advantage of having no duplicate "use". However, I also really like the style of imports_granularity = 'Module'. It's visually much clearer, and easier to modify one import without affecting other imports. Ideally, I'd love to see a style where it can combine the "one" use statement with the module style. For example,

use {
    foo::b::{f, g},
    foo::d::e,
    foo::{a, b, c},
    qux::{h, i},
};

I think imports_granularity is orthogonal to this one "use" statement style, so why not introduce a separate option like one_use_statement? With this new option, we will have 6 combinations in total:

  1. imports_granularity = 'Crate' + one_use_statement = false

  2. imports_granularity = 'Module' + one_use_statement = false

  3. imports_granularity = 'Item' + one_use_statement = false
    These 3 will be exactly the same as current

  4. imports_granularity = 'Crate' + one_use_statement = true
    This is basically identical to the current imports_granularity = 'One'

  5. imports_granularity = 'Module' + one_use_statement = true
    The example is shown above

  6. imports_granularity = 'Item' + one_use_statement = true

use {
    foo::a,
    foo::b,
    foo::b::f,
    foo::b::g,
    foo::c,
    foo::d::e,
    qux::h,
    qux::i,
};

With this new option, imports_granularity = 'One' is no longer needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions