title: How to check release / debug builds using cfg in Rust?
body: <p>With the C pre-processor it's common to do,</p>
  
  <pre><code>#if defined(NDEBUG)
      // release build
  #endif
  
  #if defined(DEBUG)
      // debug build
  #endif
  </code></pre>
  
  <p>Cargo's rough equivalents are:</p>
  
  <ul>
  <li><code>cargo build --release</code> for release.</li>
  <li><code>cargo build</code> for debug.</li>
  </ul>
  
  <p>How would Rust's <code>#[cfg(...)]</code> attribute or <code>cfg!(...)</code> macro be used to do something similar?</p>
  
  <p>I understand that Rust's pre-processor doesn't work like C's. I checked the documentation and <a href="https://doc.rust-lang.org/reference.html#conditional-compilation" rel="noreferrer">this page lists some attributes</a>. <em>(assuming this list is comprehensive)</em></p>
  
  <p><code>debug_assertions</code> could be checked, but it may be misleading when used to check for the more general debugging case.</p>
  
  <p>I'm not sure if this question should be related to Cargo or not.</p>