feat(currency): Merge all currency formatters into unified CurrencyFormatter<V> using AbstractFormatter#8189
Merged
Merged
Conversation
a49a0ae to
5414c4b
Compare
younies
approved these changes
Jul 8, 2026
younies
left a comment
Member
There was a problem hiding this comment.
Thanks @robertbastian for putting this together! This architectural direction aligns really well with my thinking—specifically, making the decimal formatter act as the underlying foundational engine that powers both currency formatters and, eventually, unit formatters. This approach will be especially beneficial once the compact currency pattern gluing proposal (CLDR-19617) is accepted.
I'm going to update the NumberFormatter design document accordingly so we can discuss and align on this new approach in our next meeting.
A few housekeeping updates:
- I fixed a minor clippy issue (an unused import), verified that formatting and all workspace tests pass cleanly, and pushed the fix to the branch.
- I updated the PR title and description to follow our conventional commits format and better reflect the architectural changes—feel free to revise them!
- I left one inline review comment for your thoughts.
| FormattedUnsignedDecimal, | ||
| }; | ||
|
|
||
| pub trait Sealed {} |
Member
There was a problem hiding this comment.
Suggested change
| pub trait Sealed {} | |
| /// An un-exportable supertrait used to seal [`AbstractFormatter`]. | |
| /// | |
| /// Because this trait is not re-exported from the crate root, downstream crates cannot | |
| /// implement it. This prevents third-party implementations of [`AbstractFormatter`], | |
| /// preserving SemVer stability and allowing internal formatting methods to evolve | |
| /// without breaking external code. | |
| pub trait Sealed {} |
TAG=agy CONV=85455991-6f0d-44c3-87be-4411f043a296
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR merges all remaining currency formatters into a single unified
CurrencyFormatter<V>type by leveragingAbstractFormatter, proposing an alternative architecture to #8182.Instead of maintaining separate representation structs or duplicating formatting data (such as
decimal_formatter,compact_data, andplural_rules),CurrencyFormatter<V>directly wraps an underlying value formatter (DecimalFormatterfor standard currency formatting orCompactDecimalFormatterfor compact currency formatting). This unifies the currency formatting architecture, simplifies pattern interpolation, and significantly reduces boilerplate across the module.Changelog
CurrencyFormatter<V>to constrainV: AbstractFormatter, allowing it to wrap eitherDecimalFormatterorCompactDecimalFormatterdirectly in a singlevalue_formatter: Vfield.try_new_short,try_new_narrow,try_new_long) initializeCurrencyFormatterwithDecimalFormatter.try_new_compact_short,try_new_compact_narrow,try_new_compact_long) initializeCurrencyFormatterwithCompactDecimalFormatter.icu_decimalDelegation: Exposedpub(crate)helper methods (format_unsigned,format_sign) and exportedFormattedUnsignedCompactDecimal/AbstractFormatterfromicu_decimalso currency formatters can delegate numeric formatting directly to the underlying value formatter.compact_formatter.rsandformatter.rs, resulting in a net code reduction of over 200 lines (+665 additions, -876 deletions).