let b: bool = 123_i32.into();
let i: i32 = true.into();
compared to
let b = 123_i32 != 0; // no "as bool" in the language
let i = true as i32;
My position is to take every possible action to reduce the uses of the as keyword which looks to my eyes too error-prone. So impl From<i32> for bool is just a bonus
Obviously this can be extended to impl From<bool> for i8 etc etc.
Slightly related: impl From<i16> for isize etc:
Update: perhaps more importantly, this is the PR to be extended by my proposal:
Every From turns into something that can be used with Into, and that is an argument conversion trait. I admit, I don’t see much realistic use for Into<i32> either. But should this function for example accept booleans automatically? I can see it sort of make sense for i8 and i16, but not bool.
I agree that we should be working towards deprecating and removing the as casting feature as it is error-prone. However, I don't think implementing these From instances should be part of that. I would say that let b = 123_i32 != 0 and let i = if b { 1 } else { 0 } are the best ways of doing the conversions you mention. Perhaps these should be put in the style guide.
<bool> as <integer type> and <integer type> as bool should just be deprecated straight away.
Because it isn't a one-bit integral type. It's a boolean logic value. It's a completely different domain.
I mean, you could argue that every type in Rust is just [i1; N] for some N, so obviously we should be able to slice a String and get an f32. But that would defeat the point of having a strong type system in the first place.
1 is no more "true" than 4, or 17, or 9275 or -8, or "banana" or vec!["coconuts", "coconuts"] or even 0. Don't forget that 0 is "true" in the UNIX shell.
"But what about the existence of Into<Vec<u8>> for String?"
I think it’s a symptom of trying to cram every kind of non-primitive conversion into a single trait. One of the reasons I started conv is that you can’t really rely on what an Into or From conversion means. They basically appear to mean “there is a conversion of some sort that will maybe succeed, that might or might not change representation and/or semantic meaning.”
In other words, they’re near completely useless in any generic context.
That said, I don’t want the situation to get worse.