Merge rust-bitcoin/rust-bitcoin#3365: Move feature flag inside impl_to_hex_from_lower_hex macro

9459739457 Move feature flag inside impl_to_hex_from_lower_hex macro (Shing Him Ng)

Pull request description:

  Moving the feature flag inside the macro definition. Since the feature flag is moved inside the macro def, we don't need to keep the definition of the one behind `#[cfg(not(feature = "alloc"))]`

  Fixes #3348

ACKs for top commit:
  apoelstra:
    ACK 9459739457 successfully ran local tests
  tcharding:
    ACK 9459739457

Tree-SHA512: 47272d3e1def21ef372af04810834da072fc43069a5c0b8ba154910d07526e79693c86cb73de301ce3d0c6cdca92abb7d23ae8346e8ce8b29c961e42e821f0e0
This commit is contained in:
merge-script 2024-09-17 15:02:34 +00:00
commit d79b5b9d43
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 4 additions and 12 deletions

View File

@ -208,13 +208,15 @@ macro_rules! impl_from_infallible {
/// Adds an implementation of `pub fn to_hex(&self) -> String` if `alloc` feature is enabled. /// Adds an implementation of `pub fn to_hex(&self) -> String` if `alloc` feature is enabled.
/// ///
/// The added function allocates a `String` then calls through to [`core::fmt::LowerHex`]. /// The added function allocates a `String` then calls through to [`core::fmt::LowerHex`].
/// Calling this macro without the `alloc` feature enabled is a noop. ///
/// Note: Calling this macro assumes that the calling crate has an `alloc` feature that also activates the
/// `alloc` crate. Calling this macro without the `alloc` feature enabled is a no-op.
#[macro_export] #[macro_export]
#[cfg(feature = "alloc")]
macro_rules! impl_to_hex_from_lower_hex { macro_rules! impl_to_hex_from_lower_hex {
($t:ident, $hex_len_fn:expr) => { ($t:ident, $hex_len_fn:expr) => {
impl $t { impl $t {
/// Gets the hex representation of this type /// Gets the hex representation of this type
#[cfg(feature = "alloc")]
pub fn to_hex(&self) -> alloc::string::String { pub fn to_hex(&self) -> alloc::string::String {
use core::fmt::Write; use core::fmt::Write;
@ -226,13 +228,3 @@ macro_rules! impl_to_hex_from_lower_hex {
} }
}; };
} }
/// Adds an implementation of `pub fn to_hex(&self) -> String` if `alloc` feature is enabled.
///
/// The added function allocates a `String` then calls through to [`core::fmt::LowerHex`].
/// Calling this macro without the `alloc` feature enabled is a noop.
#[macro_export]
#[cfg(not(feature = "alloc"))]
macro_rules! impl_to_hex_from_lower_hex {
($t:ident, $hex_len_fn:expr) => {};
}