TryFrom for bool by hkBst · Pull Request #147400 · rust-lang/rust (original) (raw)

This was previously rejected: #50597 (comment)

Thanks, that's very useful to know. Looking at that, I think the reason for rejection is best articulated by this comment from @TimNN :

The largest concern I see in the discussion above is that different people could have different expectations for the int -> bool conversion.

  1. Based on the convention 0 = success, * = error, one could argue that 0 -> Ok(true), * -> Ok(false).
  2. To be strictly in line with the bool -> int implementation from Add From for int types #50554, one could argue that 0 -> Ok(false), 1 -> Ok(true), * -> Err(()).
  3. Following the C compiler, one could argue that 0 -> Ok(false), * -> Ok(true).

I would say:

  1. this seems to be talking about what in Rust is represented by either ExitCode, which is opaque, but has impl From for ExitCode, or ExitStatus, which is also opaque, but has fn success(&self) -> bool
  2. this seems to be the obvious impl,
  3. we could, but that does not seem very Rusty, and if this is what you need, then boolean != 0 serves perfectly well,

@ithinuel previously said something in this direction here

More than 7 years have passed since the last decision, so perhaps it is not too burdensome to have another look?