mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Adds if_std! macro (#2979)
This macro compiles and executes the given code only when `std` feature is enabled. This can be useful for debugging without needing to worry that your code does not compile on `no_std`.
This commit is contained in:
@@ -30,6 +30,32 @@ macro_rules! map {
|
||||
)
|
||||
}
|
||||
|
||||
/// Feature gate some code that should only be run when `std` feature is enabled.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use sr_std::if_std;
|
||||
///
|
||||
/// if_std! {
|
||||
/// // This code is only being compiled and executed when the `std` feature is enabled.
|
||||
/// println!("Hello native world");
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_export]
|
||||
macro_rules! if_std {
|
||||
( $( $code:tt )* ) => {
|
||||
$( $code )*
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[macro_export]
|
||||
macro_rules! if_std {
|
||||
( $( $code:tt )* ) => {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
include!("../with_std.rs");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user