Skip to content

ref(taskbroker): Flatten Imports#600

Merged
george-sentry merged 1 commit intomainfrom
george/spring-cleaning/flatten-imports
Apr 20, 2026
Merged

ref(taskbroker): Flatten Imports#600
george-sentry merged 1 commit intomainfrom
george/spring-cleaning/flatten-imports

Conversation

@george-sentry
Copy link
Copy Markdown
Member

Linear

Completes STREAM-878
Completes STREAM-885

Description

Unfortunately, rustfmt combined with autocompleted imports tends to results in massive unreadable use statements with multiple layers of nesting, such as this piece of work at the top of main.rs.

use taskbroker::kafka::{
    admin::create_missing_topics,
    consumer::start_consumer,
    deserialize_activation::{self, DeserializeActivationConfig},
    inflight_activation_writer::{ActivationWriterConfig, InflightActivationWriter},
    os_stream_writer::{OsStream, OsStreamWriter},
};

Not very readable. Let's "flatten" these imports to just a single level of nesting.

use taskbroker::kafka::admin::create_missing_topics;
use taskbroker::kafka::consumer::start_consumer;
use taskbroker::kafka::deserialize_activation::{self, DeserializeActivationConfig};
use taskbroker::kafka::inflight_activation_writer::{ActivationWriterConfig, InflightActivationWriter};
use taskbroker::kafka::os_stream_writer::{OsStream, OsStreamWriter};

It's easier to read when every use statement is exactly one line, I think. Many popular Rust projects use this approach, such as serde. Here is an example from that crate.

use crate::internals::ast::{Container, Data, Field, Style};
use crate::internals::attr::{Default, Identifier, TagType};
use crate::internals::{ungroup, Ctxt, Derive};
...

It will be better on everyone's eyes to make this change, and it will also bring our codebase formatting closer to the formatting in real and widely used Rust projects.

There should be no changes to behavior.

@george-sentry george-sentry requested a review from a team as a code owner April 16, 2026 20:18
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 16, 2026

@markstory
Copy link
Copy Markdown
Member

Looks good. Is there a way to convince rustfmt / LSP autoimport to play nicely with these import groupings?

@george-sentry
Copy link
Copy Markdown
Member Author

george-sentry commented Apr 20, 2026

Looks good. Is there a way to convince rustfmt / LSP autoimport to play nicely with these import groupings?

Unfortunately no. There is an unstable rustfmt feature to control import granularity, but I don't think it will be stable any time soon (see this issue). As for the grouping / spacing, that doesn't really matter so it's okay if it's not followed.

If the import grouping is too annoying for people / AI we can drop it, just thought it would be fun to try.

@george-sentry george-sentry merged commit 76669b7 into main Apr 20, 2026
21 of 22 checks passed
@george-sentry george-sentry deleted the george/spring-cleaning/flatten-imports branch April 20, 2026 22:50
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

Successfully merging this pull request may close these issues.

2 participants