Make formatting available without alloc#1126
Closed
pitdicker wants to merge 5 commits intochronotope:0.4.xfrom
Closed
Make formatting available without alloc#1126pitdicker wants to merge 5 commits intochronotope:0.4.xfrom
alloc#1126pitdicker wants to merge 5 commits intochronotope:0.4.xfrom
Conversation
0e7d267 to
5690734
Compare
Collaborator
Author
|
Rustfmt alternates with how it wants to format the large match in |
Member
|
Let's discuss in #1127 and see whether it still makes sense to also do this. |
f4b9c50 to
773d6c4
Compare
773d6c4 to
7bafbda
Compare
Collaborator
Author
|
When we add a new formatting API I think we can do better than writing the timezone name to a fixed-size string on every use. |
This was referenced Jun 29, 2023
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.
It is possible to make the formatting methods available without the
allocfeature with relatively little changes.fmt::Formatterinstead ofString. This means replacingpush_str()withwrite_str()?, and replacingpush()withwrite_chr()?.DelayedFormatthe timezone name is rendered to aString. I have replaced this with a fixed-size buffer of 63 bytes. It was slightly tricky to get theDisplaymethod ofOffsetto format into a byte buffer, that is whatTzNameis for.Displaycan take some tricky formatting specifiers to justify/pad/truncate our formatting result. This is very difficult to do without rendering the intermediate result to aString. As solution I choose to render to an intermediate string in such a case inDisplay::fmt, and to ignore the specifiers inno_std.Part 2 and 3 seem like a small price to pay for making all these methods available to
no_stdtargets.Previously
DelayedFormatgave the impression it would work without allocations (also in the documentation), because 'why else would we have this type'? But the first thing it did was create a temporary string to write into 😆.