Skip to content

Instantly share code, notes, and snippets.

@Aatch
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aatch/5aad060daf4f5bd5946e to your computer and use it in GitHub Desktop.
Save Aatch/5aad060daf4f5bd5946e to your computer and use it in GitHub Desktop.
Handy macro for complex conditional compilation
// 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