config.phundrak.com/docs/rustfmt.org

106 lines
2.3 KiB
Org Mode
Raw Normal View History

#+TITLE: Rust Formatter
#+setupfile: headers
#+PROPERTY: header-args:toml :mkdirp yes :tangle ~/.rustfmt.toml
* Rust Formatter
The ~.rustfmt.toml~ file located in the ~$HOME~ directory is a global
configuration file for Rusts code formatters, such as ~rustfmt~. In this file,
you can find how my Rust code is always formatted.
** General settings
First, we are using the 2018 edition of Rust.
#+BEGIN_SRC toml
edition = "2018"
#+END_SRC
2023-12-10 14:09:07 +00:00
Put single-expression functions on a single line.
#+BEGIN_SRC toml
fn_single_line = true
#+END_SRC
2023-12-10 14:09:07 +00:00
Format string literals where necessary.
#+BEGIN_SRC toml
format_strings = true
#+END_SRC
2023-12-10 14:09:07 +00:00
Maximum width of each line
#+BEGIN_SRC toml
max_width = 80
#+END_SRC
2023-12-10 14:09:07 +00:00
Merge multiple imports into a single nested import.
#+BEGIN_SRC toml
merge_imports = true
#+END_SRC
** Structs and Enums
2023-12-10 14:09:07 +00:00
The maximum length of enum variant having discriminant, that gets
vertically aligned with others. Variants without discriminants would
be ignored for the purpose of alignment.
2023-12-10 14:09:07 +00:00
Note that this is not how much whitespace is inserted, but instead the
longest variant name that doesn't get ignored when aligning.
#+BEGIN_SRC toml
enum_discrim_align_threshold = 20
#+END_SRC
2023-12-10 14:09:07 +00:00
The maximum diff of width between struct fields to be aligned with
each other.
#+BEGIN_SRC toml
struct_field_align_threshold = 20
#+END_SRC
2023-12-10 14:09:07 +00:00
Reorder =impl= items. =type= and =const= are put first, then macros and
methods.
#+BEGIN_SRC toml
reorder_impl_items = true
#+END_SRC
** Comments
Convert ~/* */~ comments to ~//~ comments where possible.
#+BEGIN_SRC toml
normalize_comments = true
#+END_SRC
2023-12-10 14:09:07 +00:00
Break comments to fit on the line.
#+BEGIN_SRC toml
wrap_comments = true
#+END_SRC
2023-12-10 14:09:07 +00:00
Report ~FIXME~ items in comments.
#+BEGIN_SRC toml
report_fixme = "Always"
#+END_SRC
2023-12-10 14:09:07 +00:00
Report ~TODO~ items in comments.
#+BEGIN_SRC toml
todo = "Always"
#+END_SRC
** Documentation
Format code snippet included in doc comments.
#+BEGIN_SRC toml
format_code_in_doc_comments = true
#+END_SRC
2023-12-10 14:09:07 +00:00
Convert ~#![doc]~ and ~#[doc]~ attributes to ~//!~ and ~///~ doc comments.
#+BEGIN_SRC toml
normalize_doc_attributes = true
#+END_SRC
** Whitespace
Use tab characters for indentation, spaces for alignment.
#+BEGIN_SRC toml
hard_tabs = false
#+END_SRC
2023-12-10 14:09:07 +00:00
Number of spaces per tab.
#+BEGIN_SRC toml
tab_spaces = 4
#+END_SRC
2023-12-10 14:09:07 +00:00
I want newlines to always be Unix style.
#+BEGIN_SRC toml
newline_style = "Unix"
#+END_SRC