Hi, I'm Eric.

I’m an avid world traveler, photographer, software developer, and digital storyteller.

I help implement the Content Authenticity Initiative at Adobe.

Use the built-in code formatter

15 February 2026

One of the things I love about the Rust ecosystem is rustfmt.

It’s the standard code formatter for Rust, and it ships with the standard toolchain. That means everyone can format their code the same way with zero configuration.

When I start a new Rust project, one of the first things I do is make sure rustfmt is part of the workflow. I typically set up a pre-commit hook or CI check so that unformatted code can’t sneak in. That way, I never have to think about where to put braces or how to break long lines — the tool handles it for me.

Why this matters

Automated formatters remove a whole category of decisions from my brain. I don’t have to argue with myself (or my collaborators) about style; the formatter is the arbiter.

This also means that when I’m reviewing code changes, I’m not distracted by formatting differences. I can focus on what the code does rather than how it’s laid out.

About that “zero configuration” thing …​

Okay, I’ll confess: I do actually configure rustfmt. So much for zero configuration, right?

Here’s the rustfmt.toml file that I typicaly use in my projects:

blank_lines_upper_bound = 1
empty_item_single_line = true
format_code_in_doc_comments = true
group_imports = "StdExternalCrate"
hex_literal_case = "Lower"
imports_granularity = "Crate"
reorder_impl_items = true
unstable_features = true
wrap_comments = true

Let me walk through some of these choices:

  • blank_lines_upper_bound = 1 — I use vertical whitespace intentionally (more on that in the next page), so I don’t want the formatter removing my blank lines. But I also don’t need two blank lines anywhere, so this keeps things tidy.

  • format_code_in_doc_comments = true — I spend a lot of time writing documentation, and code examples in docs should be formatted consistently with the rest of the codebase.

  • group_imports = "StdExternalCrate" — This organizes use statements into groups: standard library first, then external crates, then the current crate. It makes it easier to scan imports at a glance.

  • imports_granularity = "Crate" — This consolidates imports from the same crate into a single use statement. Less visual noise.

  • wrap_comments = true — Long comments get wrapped to fit within the line length. Consistent formatting, even in prose.

Some of these options require the nightly version of rustfmt, hence the unstable_features = true setting.

Other languages

Not every language has a formatter as universally adopted as rustfmt, but many have good options. If your language of choice has a widely-adopted formatter, I’d encourage you to use it. The specific formatting choices matter far less than the consistency you gain.

If you’ve enjoyed this …

Subscribe to my free and occasional (never more than weekly) e-mail newsletter with my latest travel and other stories:

Or follow me on one or more of the socials: