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?
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?
This is just a hack, but you could use something like this:
#[cfg(feature = "alwaysfalse")]
println!("this will never be printed");
#[cfg(not(feature = "alwaysfalse"))]
println!("this will always be printed");
This will break down if you add the alwaysfalse
feature to your Cargo.toml
, and then compile with cargo build --features alwaysfalse
... But that's under your control.
Cool! That should work. Thank you!
fn main() {
#[cfg(any())]
println!("Never");
#[cfg(all())]
println!("Always");
}
Output:
Always
Amazing! It is even better! Thanks!