From 1bb32febbdc00d878f03c73c3d07b32a29fac9b9 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 3 Apr 2024 11:14:32 +1100 Subject: [PATCH] Use manual docs attributes Currently we are using `Self` (in backticks) in the docs to functions defined by the `do_iml` macro, this is a bit lazy, we can do better than that. Use `doc` attribute and the `$ty` macro variable to construct the docs to use the type name. --- bitcoin/src/pow.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index 50c30ab6..5dbb9482 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -24,29 +24,41 @@ use crate::error::{ContainsPrefixError, MissingPrefixError, ParseIntError, Prefi macro_rules! do_impl { ($ty:ident) => { impl $ty { - /// Creates `Self` from a prefixed hex string. + #[doc = "Creates `"] + #[doc = stringify!($ty)] + #[doc = "` from a prefixed hex string."] pub fn from_hex(s: &str) -> Result { Ok($ty(U256::from_hex(s)?)) } - /// Creates `Self` from an unprefixed hex string. + #[doc = "Creates `"] + #[doc = stringify!($ty)] + #[doc = "` from an unprefixed hex string."] pub fn from_unprefixed_hex(s: &str) -> Result { Ok($ty(U256::from_unprefixed_hex(s)?)) } - /// Creates `Self` from a big-endian byte array. + #[doc = "Creates `"] + #[doc = stringify!($ty)] + #[doc = "` from a big-endian byte array."] #[inline] pub fn from_be_bytes(bytes: [u8; 32]) -> $ty { $ty(U256::from_be_bytes(bytes)) } - /// Creates `Self` from a little-endian byte array. + #[doc = "Creates `"] + #[doc = stringify!($ty)] + #[doc = "` from a little-endian byte array."] #[inline] pub fn from_le_bytes(bytes: [u8; 32]) -> $ty { $ty(U256::from_le_bytes(bytes)) } - /// Converts `self` to a big-endian byte array. + #[doc = "Converts `"] + #[doc = stringify!($ty)] + #[doc = "` to a big-endian byte array."] #[inline] pub fn to_be_bytes(self) -> [u8; 32] { self.0.to_be_bytes() } - /// Converts `self` to a little-endian byte array. + #[doc = "Converts `"] + #[doc = stringify!($ty)] + #[doc = "` to a little-endian byte array."] #[inline] pub fn to_le_bytes(self) -> [u8; 32] { self.0.to_le_bytes() } }