Expand description
A C++ formatter whose configuration is clang-format’s.
The crate is built in the order the design document measures, and each module says which step of that order it is:
config `.clang-format` and the seven presets, as a flattened key/value style
tokens the token stream with its trivia split into "gaps" (the only regions a formatter may rewrite)
roles what a token *is* — template angle, declarator, block brace — read from the syntax tree
space the width between two tokens that stay on one line
render the source with those widths substituted, and nothing else touchedWhat is not here yet, and is the next step (layout.rs): where the line breaks go and how deep each line
sits. Until then [format] keeps the input’s line structure, which makes the tool safe to run on a file and
lets the spacing decisions be audited against clang-format on their own (examples/spacing_audit.rs).
Re-exports§
pub use config::ConfigError;pub use config::Style;
Modules§
- breaks
- Logical lines: the unit a line breaker works on.
- columns
- The column model: what a column number means.
- config
.clang-format: the YAML subset clang-format itself accepts, and the style it resolves to.- includes
- P3: sorting an include block.
- layout
- How deep each line sits.
- macros
AlignEscapedNewlines: the backslashes of a multi-line macro.- options
- Every style option, as a Rust enum whose discriminant is its index in crate::config::Style.
- output
-output-replacements-xml: the formatter’s answer as clang-format’s replacement list.- presets
- The seven built-in presets, flattened to
key/valuestrings. - regions
// clang-format off…// clang-format onandDisableFormat.- render
- The renderer: the source with new whitespace, and not one other byte changed.
- roles
- What a token is, where the token stream alone cannot say — read from the syntax tree.
- rows
AlignArrayOfStructures: Left— the columns of a braced table.- space
- Where the spaces go between two tokens that stay on the same line.
- tokens
- The token stream a formatter needs: every token, and the trivia between them.
- trailing
- Where a trailing comment starts:
AlignTrailingCommentswithSpacesBeforeTrailingComments.
Functions§
- format
- Format
sourcewithstyle, keeping the source’s line structure. - format_
file - Format
sourceas the file atpath, which is what lets the include sorter put the file’s own header first (clang-format’s main-header rule; seeincludes.rs). - format_
range - Format only the lines
first..=last(0-based), the library half of clang-format’s-lines. - format_
with_ config - Format
sourcewith the style thattext(a.clang-format) describes.