feat: no-allocation hex-encoding using HexWriter
#86
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.
HexWriter
allows to directly hex-encode binary data to astd::fmt::Write
object from any source that can write to astd::io::Write
object. This saves between one and two allocations depending on the use case.Let's assume a function
Foo::encode(&self, writer: std::io::Write) -> Result<(), std::io::Error>
:Foo
object toFormatter
as hex would require 2 allocations: one to encode bytes into aVec<u8>
and a second to encode the bytes into aString
before writing it to theFormatter
. Here we can save 2 allocations.Foo
struct as hex into aString
, here we only save 1 allocation (the intermediate byte step)Vec<u8>
as hex to aFormatter
: 1 allocation saved (String
)