Defining cfg in a source file (default/fallback)

I am looking for help for defining a 'fallback' configuration
In C, I would use

#ifdef special_1
#define have_special
.. special stuff
#endif

#ifdef special_2
#define have_special
.. more special stuff
#endif

#ifndef have_special
.. define a fallback
#endif

How do I do this in Rust? I reckon I can do
#[cfg(special_1)]
...
#[cfg(special_2)]
...
#[cfg(not(any(special_1,special_2))]
...

but that seems a bit more error prone as opposed to just picking off special cases if defined and a generic fallback.

cfg_if provides a macro that lets you write cfgs in an "if else" style like that

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.