rust-lang / rust-lang/rust-by-example
Activity for 1.2.2 Display - Formatting a Complex Struct
Nobody has claimed this yet.
- Dominant language
- Handlebars
- Stars
- 8.1k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
I am having some difficulty with achieving the activity in 1.2.2 Display due to the presence of a space between the sign and the imaginary component.
The activity asks to add a fmt::Display implementation for a struct representing a complex number with real and imaginary f64 values with the output:
3.3 + 7.2i
Using "{} {:+}i" would seem like the reasonable approach but this yields 3.3 +7.2i and it is not obvious how I can pad between the sign and imaginary component to get the output specified. As the activity doesn't test complex numbers with a negative imaginary component, some folks might just use "{} + {}i" and move on to the next lesson.
So am I missing something - is there a way to add padding? should I use some conditional statement based on the sign of the imaginary component?
I noticed this change was introduced by PR #1123 where previous to this, there was no space.
Cheers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the 1.2.2 Display activity at hello/print/print_display.html and review PR #1123 for the formatting change that introduced the discrepancy. Determine how the exercise should represent both positive and negative imaginary values, then update the activity so its requested output and guidance are unambiguous.
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
- 52/100