`#[cfg]` attrib vs `cfg!` macro in Rust

When I published my previous post on mastodon, Sebastian pointed out 1 that using #[cfg] is better than cfg! macro.

Documentation explains that :

cfg!, unlike #[cfg], does not remove any code and only evaluates to true or false. For example, all blocks in an if/else expression need to be valid when cfg! is used for the condition, regardless of what cfg! is evaluating.

Thanks, Sebastian!


  1. See this thread for the original discussion. ↩︎