And I wonder if that is just plain silly. I don't mean the specific feature and function names being silly, but the logic. Using a loop, not for looping but just for breaking out of it with a value?
I mean, I have a list of cfg's and checking their related functions true/false state. And want to check if they are all true or all false. I would rather just chain them with an if using "&&" but could not get the syntax to work with the cfg's.
if #[cfg(feature = "cats")]
&& #[cfg(feature = "dogs")]
And rustfmt makes that ugly anyway.
What is the idiomatic way to check a list of conditionals that are included with features cfg's?
Thanks for reminding me, I will check it out and see how it works in this situation. I did try to use it in the past at a couple of other code points where I have a list of cfg's in function signature generic traits. The cfg-if macro borks in function signatures.
If the functions are always defined which admittedly is probably not likely when using features, this is another option. I would think the function calls for missing features would get optimized away (which seems to be confirmed by godbolt for this simple example)
I think the most obvious hasn't been said yet. I don't personally agree that you should play tricks with loops, labels, or even closures in this particular case. If you have some non-trivial configuration and logic going on, then simply extract it into a function, which makes it trivial to return early if that's what you need. That will be much easier to understand later.
Personally I think "loop" has an intended meaning. That is to do something multiple times. This is what it communicates to anyone reading your code. Given that your code only ever does one thing once it is misleading to any reader to wrap that up in a loop.
Similarly with other language constructs. In general one should try and express what it is one is wanting to do. Not obfuscate it with language constructs intended for other purposes.
Thank you to you and @H2CO3 for your firmness. After sawing wood and pounding nails for a couple of days, your advice's bouncing through my head. And clippy yelled at me too for using a loop that does not loop. I rethough things. Keep it simple So after I left the code alone and came back to it I do not need any 'loop" that does not loop and my cfg's are much less. I did not even need to put anything into a function. I did not
and things are much clearer.
Also this point really helped me get focused.
Just want to say thanks again for the support and thanks for your patience.
Rust. Empowering everyone even space cadets..