Clean up function comments and visibility in hex_codec
What changed, and why it matters
This is a minor code cleanup change in a Rust Bitcoin library. It changes one internal field from being publicly visible to being visible only within the crate, and updates some documentation comments. There is no security issue here.
No action needed. This is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit changes HexPrimitive’s inner field from pub &'a T to pub(crate) &'a T, matching the struct’s own pub(crate) visibility. The module is intended to be crate-internal, so this simply corrects an inconsistency. Documentation comments were also reworded for clarity. No functional behavior changed.
Changed components
primitives/src/hex_codec.rsInspect captured patch +7 / −8
diff --git a/primitives/src/hex_codec.rs b/primitives/src/hex_codec.rs
index 075ef05b..b4edf8d2 100644
--- a/primitives/src/hex_codec.rs
+++ b/primitives/src/hex_codec.rs
@@ -15,12 +15,11 @@ use encoding::{Decodable, Decoder, Encodable, EncodableByteIter};
use hex_unstable::{BytesToHexIter, Case};
use internals::write_err;
-/// Hex encoding wrapper type for Encodable + Decodable types.
+/// Hex encoding wrapper type for `Encodable` + `Decodable` types.
///
-/// Provides default implementations for `Display`, `Debug`, `LowerHex`, and `UpperHex`.
-/// Also provides [`Self::from_str`] for parsing a string to a `T`.
-/// This can be used to implement hex display traits for any encodable types.
-pub(crate) struct HexPrimitive<'a, T: Encodable + Decodable>(pub &'a T);
+/// Implements `Display`, `Debug`, `LowerHex`, and `UpperHex` as well as an inherent `from_str`
+/// method that returns `T`.
+pub(crate) struct HexPrimitive<'a, T: Encodable + Decodable>(pub(crate) &'a T);
impl<'a, T: Encodable + Decodable> IntoIterator for &HexPrimitive<'a, T> {
type Item = u8;
@@ -32,15 +31,15 @@ impl<'a, T: Encodable + Decodable> IntoIterator for &HexPrimitive<'a, T> {
impl<T: Encodable + Decodable> HexPrimitive<'_, T> {
/// Parses a given string into an instance of the type `T`.
///
- /// Since `FromStr` would return an instance of Self and thus a &T, this function
+ /// Since `FromStr` would return an instance of `Self` and thus a &T, this function
/// is implemented directly on the struct to return the owned instance of T.
/// Other `FromStr` implementations can directly return the result of
/// [`HexPrimitive::from_str`].
///
/// # Errors
///
- /// [`ParsePrimitiveError::OddLengthString`] if the input string is an odd length.
- /// [`ParsePrimitiveError::Decode`] if an error occurs during decoding of the object.
+ /// * `OddLength` or `InvalidChar` if decode the hex string to bytes fails.
+ /// * `Decode` if consensus decoding the hex-decoded bytes fails.
pub(crate) fn from_str(s: &str) -> Result<T, ParsePrimitiveError<T>> {
let iter = hex_unstable::HexToBytesIter::new(s)?;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.