Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce hex::display for Display’ing binary data in hex #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mina86
Copy link

@mina86 mina86 commented Jul 19, 2023

encode method allocates a new string which is wasteful if all one
wants to do is display the binary data using format! or related macro.

Introduce hex::Display wrapper with hex::display as its constructor
which wraps the binary data in an object that implements Display,
LowerHex, UpperHex and Debug and formats the data as hex. However, as
it uses buffers on stack, it performs no allocations.

@mina86
Copy link
Author

mina86 commented Nov 11, 2023

@KokaKiwi, friendly ping.

Copy link

@hkBst hkBst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea! Where are the tests?

encode method allocates a new string which is wasteful if all one
wants to do is display the binary data using format! or related
macro.

Introduce hex::Display wrapper with hex::display as its constructor
which wraps the binary data in an object that implements Display,
LowerHex, UpperHex and Debug and formats the data as hex.  However,
as it uses buffers on stack, it performs no allocations.
@mina86
Copy link
Author

mina86 commented Dec 31, 2024

In the docstring. Added more tests in code.


assert_eq!(generate_iter(5).collect::<Vec<_>>(), result);
}

const TEST_CASES: [(&[u8], &str, &str); 5] = [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if you make this a slice, then you don't need to specify the size: const TEST_CASES: &[...] = &[...];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants