Custom

Some conditionals like target_os are implicitly provided by rustc, but
custom conditionals must be passed to rustc using the --cfg flag.

  1. #[cfg(some_condition)]
  2. fn conditional_function() {
  3. println!("condition met!");
  4. }
  5. fn main() {
  6. conditional_function();
  7. }

Try to run this to see what happens without the custom cfg flag.

With the custom cfg flag:

  1. $ rustc --cfg some_condition custom.rs && ./custom
  2. condition met!