Move feature flag inside impl_to_hex_from_lower_hex macro

This commit is contained in:
Shing Him Ng 2024-09-16 08:27:05 -05:00
parent 85fa0ce28d
commit 9459739457
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.
///
/// 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]
#[cfg(feature = "alloc")]
macro_rules! impl_to_hex_from_lower_hex {
($t:ident, $hex_len_fn:expr) => {
impl $t {
/// Gets the hex representation of this type
#[cfg(feature = "alloc")]
pub fn to_hex(&self) -> alloc::string::String {
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) => {};
}