Alignment of horizontally-formatted enum struct variants
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 48/100
Direzione di ricerca
Inizia studiando come le opzioni correlate struct_field_align_threshold e enum_discrim_align_threshold sono implementate e testate in rustfmt. Traccia come vengono gestite le varianti di struct degli enum formattate orizzontalmente, quindi definisci il comportamento della configurazione e i test per i limiti della soglia, max_width, il valore disabilitato per impostazione predefinita e l'output allineato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature Request
struct_variant_align_threshold
Summary
For applicable, horizontally-formatted branches of an enum with struct variants, aligns them by adding padding space after each branch name, so all struct variants start at the same column (one space after the longest branch name). This is used in good combination with the stable option struct_variant_width.
When enabled, this is applied to all branches when their name is shorter than threshold, and adding the padding does not exceed max_width. The default value would be 0 to disable it, with any nonnegative integer as a possible value.
Motivation
A good example is an enum where many struct variants have the same or similar fields, allowing for much greater readability of the branch names. This is particularly common on enums that have many shared fields, and many, many variants. An example is the Instruction enum on uutils awk:
Original (snippet):
pub enum Instruction {
Record { dest: Reg, arg: Arg, ty: ArgTy },
Negation { dest: Reg, arg: Arg, ty: ArgTy },
ToInt { dest: Reg, arg: Arg, ty: ArgTy },
Negative { dest: Reg, arg: Arg, ty: ArgTy },
...
Matches { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
MatchesNot { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Add { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Subtract { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
...
}
Formatted (new):
pub enum Instruction {
Record { dest: Reg, arg: Arg, ty: ArgTy },
Negation { dest: Reg, arg: Arg, ty: ArgTy },
ToInt { dest: Reg, arg: Arg, ty: ArgTy },
Negative { dest: Reg, arg: Arg, ty: ArgTy },
...
Matches { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
MatchesNot { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Add { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Subtract { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
...
}
Note: I know this particular case can be solved using a newtype or an alias, but we have our reasons for it to be this way in the real codebase. Believe me, this enum was not born this way.
Related configuration options
struct_field_align_threshold, enum_discrim_align_threshold
- Lingua principale
- Rust
- Stelle
- 7.1k
- Fork
- 1.2k
- Merge medio
- 1g 4h
- PR unite (30g)
- 20
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/rustfmt
-
A-config C-bug SO-print-config
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
A-Unicode C-bug P-low
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
rust-lang/rustfmt#7210 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rust-lang/rustfmt#7173 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
A-comments C-bug only-with-option UO-indent_style
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Fix `first_line_width` to be tab-awareForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaA-tabs A-whitespace C-bug SO-hard_tabs
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rust-lang/rustfmt
Issue simili
-
bug P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug core-lang
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Windows microphone listing treats words in a device name as DirectShow labelsForse già presa @Sujal-chaudhary l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
clipy-recorder/clipy#447 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
nightly-cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
max-sixty/worktrunk#4939 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno