Skip to content

Add fmt_hex_exact_lower and fmt_hex_exact_upper macros#247

Open
alexgrad42 wants to merge 1 commit into
rust-bitcoin:masterfrom
alexgrad42:feature/fmt_hex_exact_lower_and_upper
Open

Add fmt_hex_exact_lower and fmt_hex_exact_upper macros#247
alexgrad42 wants to merge 1 commit into
rust-bitcoin:masterfrom
alexgrad42:feature/fmt_hex_exact_lower_and_upper

Conversation

@alexgrad42
Copy link
Copy Markdown
Contributor

The implementation wraps the existing fmt_hex_exact! macro to minimize code duplication and keep it clean.

Fixes: #246

@alexgrad42 alexgrad42 force-pushed the feature/fmt_hex_exact_lower_and_upper branch from a32d557 to a1c5829 Compare May 11, 2026 08:56
@apoelstra
Copy link
Copy Markdown
Member

concept ACK. can you undraft?

@alexgrad42 alexgrad42 marked this pull request as ready for review May 11, 2026 13:18
@alexgrad42 alexgrad42 force-pushed the feature/fmt_hex_exact_lower_and_upper branch from a1c5829 to be4b0ed Compare May 11, 2026 13:34
@tcharding
Copy link
Copy Markdown
Member

New discussion on the issue needs addressing please mate. Thanks for the prompt contribution also!

@alexgrad42 alexgrad42 force-pushed the feature/fmt_hex_exact_lower_and_upper branch 4 times, most recently from e4f09d5 to d0726a9 Compare May 12, 2026 17:26
Comment thread src/display.rs
/// ## Panics
///
/// This macro panics if `$len` is not equal to `$bytes.len()`
///
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be removed, rather it should be updated to say that it will panic if the length of the encoded item is larger than $len.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, please check

Comment thread src/display.rs
// statically check $len
#[allow(deprecated)]
const _: () = [()][($len > usize::MAX / 2) as usize];
$crate::display::fmt_hex_max_fn::<_, { $len * 2 }>($formatter, $bytes, $case)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Length check is missing here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, please check

@alexgrad42 alexgrad42 force-pushed the feature/fmt_hex_exact_lower_and_upper branch from d0726a9 to 1e29af7 Compare May 13, 2026 06:20
- Added fmt_hex_max! macro which provides compile-time verification of the length.
- Added fmt_hex_lower! and fmt_hex_upper! macros for convenient hex formatting.

Fixes: rust-bitcoin#246
@alexgrad42 alexgrad42 force-pushed the feature/fmt_hex_exact_lower_and_upper branch from 1e29af7 to a9d2032 Compare May 13, 2026 06:23
Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK a9d2032

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.

Add macros for lower and upper

4 participants