Skip to content

Add examples to hex iterator constructors#241

Merged
apoelstra merged 1 commit intorust-bitcoin:masterfrom
mpbagot:feature/iter-examples
Apr 21, 2026
Merged

Add examples to hex iterator constructors#241
apoelstra merged 1 commit intorust-bitcoin:masterfrom
mpbagot:feature/iter-examples

Conversation

@mpbagot
Copy link
Copy Markdown
Contributor

@mpbagot mpbagot commented Apr 20, 2026

The hex -> bytes iterators in the iter module are visible in the public api but don't have any code examples attached to them. While they're reasonably self-explanatory, some short example snippets on the constructors should make sure that it's absolutely unambiguous how they're to be used.

Add example to HexSliceToBytesIter::new and HexBytesToIter::from_pairs.

The hex -> bytes iterators in the iter module are visible in the public
api but don't have any code examples attached to them. While they're
reasonably self-explanatory, some short example snippets on the
constructors should make sure that it's absolutely unambiguous how
they're to be used.

Add example to HexSliceToBytesIter::new and HexBytesToIter::from_pairs.
@mpbagot mpbagot force-pushed the feature/iter-examples branch from bb07974 to 2e9594a Compare April 20, 2026 09:23
Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 2e9594a; successfully ran local tests

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 2e9594a

@tcharding
Copy link
Copy Markdown
Member

The two lines of /// # } bothered me so I tried to refactor the test. Also to make it easier to read in the editor (I don't have syntax highlighting in my editor for rustdocs still). Totally optional, you have 2 acks already.

    /// ```
    /// # #[cfg(feature = "std")] {
    /// # use hex_conservative::HexToBytesIter;
    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///
    /// let hex_digits: Vec<u8> = b"deadbeef".iter().copied().collect();
    /// let pairs = hex_digits.chunks_exact(2).map(|c| [c[0], c[1]]);
    ///
    /// let decoded:  = HexToBytesIter::from_pairs(pairs).collect::<Result<_, _>>()?;
    /// assert_eq!(decoded, [0xde, 0xad, 0xbe, 0xef]);
    ///
    /// # Ok(()) }}
    /// ```

@tcharding tcharding mentioned this pull request Apr 20, 2026
6 tasks
@tcharding
Copy link
Copy Markdown
Member

Oh my version renders poorly because of the new lines. Please ignore.

@apoelstra apoelstra merged commit a2e2250 into rust-bitcoin:master Apr 21, 2026
15 checks passed
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.

3 participants