rust

`cfg` which is always true / false?


For testing purpose I need cfg which is always true / false. For true I use

#[ cfg( target_pointer_width = "64") ]
...

But obviously it is not general enough. What is optimal way of expressing cfg to get necessary value?


Solution

  • Just do this for a cfg option that is always true:

    #[cfg(all())]
    fn main() {
        println!("It works!");
    }
    

    And if you need a cfg option that is always false you can use:

    #[cfg(any())]
    fn main() {
        println!("It disappears!");
    }