rust-lang / rust-lang/rust-by-example

Mistake in comments about right-alignement in string formatting

Open Beginner friendly
#1,581 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Handlebars
Stars
8.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

In an early example, we can see these lines:

    // You can right-align text with a specified width. This will output
    // "     1". 5 white spaces and a "1".
    println!("{number:>5}", number=1);

    // You can pad numbers with extra zeroes. This will output "000001".
    println!("{number:0>5}", number=1);

However the comments are wrong. The number of spaces and zeroes added won't be five, but only enough so that the string is of length 5. In this particular case, only four spaces and zeroes are added, as can be seen by simply running the example (after solving the FIXMEs).

Contributor guide

Open the contributing guide

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

Open the early formatting example at doc.rust-lang.org/stable/rust-by-example/hello/print.html and run the shown Rust snippets after resolving the FIXMEs. Update the comments so they describe the total width and actual padding, then verify the example output matches the wording.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.