[rust-dev] conditional compilation and macros

Maciej Dziardziel fiedzia at gmail.com
Fri Apr 4 21:05:01 PDT 2014


I am trying to define macro that would only expand to anything
if certain cfg option is defined, otherwise it should be no-op,
but I cannot find a way to do it. Pretty much I want some form of #ifdef.

The closest thing I can find is to enclose generated code in a function, and
just do this:

#cfg(foo)]
def foo(){
//do something
}

#[cfg(not(foo))]
def foo()){}


Is there a better way to do that?

-- 
Maciej Dziardziel
fiedzia at gmail.com


More information about the Rust-dev mailing list