mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
5a0682c1e0
* replace derive_more's 'From' in signer * replace derive_more's 'From' in core * Remove `derive_more`'s `Display` usages (#1601) * Remove derive_more's 'Display' from core * Remove derive_more's 'Display' from metadata * Remove derive_more's 'Display' from signer * Remove derive_more from dependencies (#1602) closes #1503 * Update signer/src/eth.rs Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> * rename convert_error to impl_from * rename convert_error to impl_from in core --------- Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
|
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
|
// see LICENSE for license details.
|
|
|
|
#![allow(unused_macros)]
|
|
|
|
/// Use like:
|
|
///
|
|
/// ```rust,ignore
|
|
/// once_static_cloned!{
|
|
/// /// Some documentation.
|
|
/// fn foo() -> Vec<u8> {
|
|
/// vec![1,2,3,4]
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
///
|
|
/// Clones the item out of static storage. Useful if it
|
|
/// takes a while to create the item but cloning it is fairly cheap.
|
|
macro_rules! once_static_cloned {
|
|
($($(#[$attr:meta])* $vis:vis fn $name:ident() -> $ty:ty { $expr:expr } )+) => {
|
|
$(
|
|
$(#[$attr])*
|
|
$vis fn $name() -> $ty {
|
|
cfg_if::cfg_if! {
|
|
if #[cfg(feature = "std")] {
|
|
static VAR: std::sync::OnceLock<$ty> = std::sync::OnceLock::new();
|
|
VAR.get_or_init(|| { $expr }).clone()
|
|
} else {
|
|
{ $expr }
|
|
}
|
|
}
|
|
}
|
|
)+
|
|
};
|
|
}
|
|
|
|
macro_rules! impl_from {
|
|
($module_path:path => $delegate_ty:ident :: $variant:ident) => {
|
|
impl From<$module_path> for $delegate_ty {
|
|
fn from(val: $module_path) -> Self {
|
|
$delegate_ty::$variant(val.into())
|
|
}
|
|
}
|
|
};
|
|
}
|