diff --git a/substrate/core/sr-std/src/lib.rs b/substrate/core/sr-std/src/lib.rs index b9874bcc20..24c137c285 100644 --- a/substrate/core/sr-std/src/lib.rs +++ b/substrate/core/sr-std/src/lib.rs @@ -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");