so when i learned about Cargo features and that they even work in enums i thought i could use that to select features in my program.
I also thought that the cfg!() macro would work as well, but apparently it does not in this case:
See Rust Playground
I find this example working when i remove the "#[cfg(feature = "testfeature")]" from the enum.
But when i add this line (and since the playpen doesn't enable this feature, the enum will be missing SomeFeature), the compilation fails, because SomeFeature is not available. Of course my hope was that the macro would remove the block containing SomeFeature..
Is this just something that is not supposed to work and my misunderstanding or some edge case that may be a future feature?
Seems like you messed up #[cfg] and #[feature] attributes and cfg!() macro.
The #[cfg] attribute is for conditional compilation, when you put it above some block/expression/statement, it means it will be ignored by compiler unless it is called with --cfg something.
You can turn compiler features on with #[feature] attribute, but it doesn't have anything in common with #[cfg] and cfg!.
The cfg!() macro just returns true if the compiler is called with --cfg something, false otherwise. It's like a function, which value is controlled with the compiler's argument.
Upd. As mentioned above, I missed the point cfg!()/#[cfg] can contain more complex compile-time "expression", including checks for turned on features. But the main point is still this: #[cfg] is like #ifdef FEATURE ... #endif (conditional compilation) on steroids, and cfg!() is like a "function" with boolean output.
I compared the two command line messages, the first one with testfeature has a --cfg 'feature="testfeature"' in it which the second one don't have this.