Last active
August 29, 2015 14:21
-
-
Save Aatch/5aad060daf4f5bd5946e to your computer and use it in GitHub Desktop.
Handy macro for complex conditional compilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Feel free to copy and modify this code if it's useful to you. | |
macro_rules! if_cfg { | |
($(#[cfg($cfg:meta)] $it:item)+ fallback: $els:item) => ( | |
$(#[cfg($cfg)] $it)+ | |
#[cfg(not(any($($cfg),*)))] $els | |
) | |
} | |
if_cfg { | |
#[cfg(target_arch="x86")] | |
fn arch() -> &'static str { "x86" } | |
#[cfg(target_arch="arm")] | |
fn arch() -> &'static str { "arm" } | |
fallback: | |
fn arch() -> &'static str { "other" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment