It is possible for any type in Rust to define how they can be used in a
for expression, allowing them to integrate into the language and define their behavior, if desired.
However, this is not possible for
if expressions, and it’s left to the user to call the right functions, even sometimes
.into::<bool>(), on the condition expression to provide the
if expression with the only type supported,
Since there already exists a core and native way of possibly converting any time into
Iter traits, it is possible to improve the user experience by calling
.into::<bool>() automatically, if defined, for the condition expression, whenever the type is not
What do you think? Has this been considered in the language? Are there any drawbacks?
NOTE: There’s no suggestion here to implement
Into<bool> for any primitive types, like
i32, or other core types, like
Option, here. The possible confusions that may arise from these cases is already explored and well-understood.