rust-lang / rust-lang/rfcs

style guide: recommend against frequent tuple indexing

Open
#581 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-doc
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

I would like the style guide to suggest avoiding frequent tuple indexing. Something along the lines of, "if you are frequently using tuple indexing, consider changing to use a tuple-struct or struct in order to be clear about the nature of fields".

My motivation is that foo.3 gives no indication about the 4th field at all. Whereas foo.position tells you a lot more about the field. Tuple indexing should only be used where the tuple is mostly destructured and there are exceptional cases of field access. If the common access pattern is field access, then a structure with named fields is more appropriate.

cc @aturon

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name a file, test, or documentation entry point. Locate the style guide in the rfcs repository, review its guidance on tuple indexing and named fields, and confirm that the recommendation is added there with wording that clearly explains when tuple structs or structs are preferable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.