app_crypto: macro improvements (#14263)

* app_crypto: macro improvements

During `app_crypto`  macro expansion the `cfg` feature gate was injected
  into the macro client crate. This resulted in compilation error if
`serde` or `std` was not defined in client crate. This PR fixes this
problem.

For reference, the error was:

```
  error: cannot find macro `format` in this scope
    --> /home/miszka/parity/10-genesis-config/substrate-2/primitives/consensus/aura/src/lib.rs:32:3
     |
  32 |         app_crypto!(sr25519, AURA);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
...

  error[E0433]: failed to resolve: use of undeclared type `String`
    -->
/home/miszka/parity/10-genesis-config/substrate-2/primitives/consensus/aura/src/lib.rs:32:3
     |
  32 |         app_crypto!(sr25519, AURA);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared type `String`
```

* app_crypto: cleanup
This commit is contained in:
Michal Kucharczyk
2023-05-30 13:15:13 +01:00
committed by GitHub
parent 263a5d6c1e
commit e7e13116f7
@@ -32,9 +32,6 @@ pub use sp_core::{
crypto::{ByteArray, CryptoType, Derive, IsWrappedBy, Public, UncheckedFrom, Wraps},
RuntimeDebug,
};
#[doc(hidden)]
#[cfg(all(not(feature = "std"), feature = "serde"))]
pub use sp_std::alloc::{format, string::String};
#[doc(hidden)]
pub use codec;
@@ -328,6 +325,14 @@ macro_rules! app_crypto_public_common {
};
}
#[doc(hidden)]
pub mod module_format_string_prelude {
#[cfg(all(not(feature = "std"), feature = "serde"))]
pub use sp_std::alloc::{format, string::String};
#[cfg(feature = "std")]
pub use std::{format, string::String};
}
/// Implements traits for the public key type if `feature = "serde"` is enabled.
#[cfg(feature = "serde")]
#[doc(hidden)]
@@ -365,9 +370,7 @@ macro_rules! app_crypto_public_common_if_serde {
where
D: $crate::serde::Deserializer<'de>,
{
use $crate::Ss58Codec;
#[cfg(all(not(feature = "std"), feature = "serde"))]
use $crate::{format, String};
use $crate::{module_format_string_prelude::*, Ss58Codec};
Public::from_ss58check(&String::deserialize(deserializer)?)
.map_err(|e| $crate::serde::de::Error::custom(format!("{:?}", e)))