Make formatting available without alloc
#1126
Closed
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
alloc
feature with relatively little changes.fmt::Formatter
instead ofString
. This means replacingpush_str()
withwrite_str()?
, and replacingpush()
withwrite_chr()?
.DelayedFormat
the timezone name is rendered to aString
. I have replaced this with a fixed-size buffer of 63 bytes. It was slightly tricky to get theDisplay
method ofOffset
to format into a byte buffer, that is whatTzName
is for.Display
can 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_std
targets.Previously
DelayedFormat
gave 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 😆.