Open mattsse opened 3 days ago
Thanks for the contribution. Rust convention is to use From
and TryFrom
for conversions. I do not think we should add from_i32
back in.
to_i32()
however seems useful and IMO probably should not have been removed, we could also add to_u8
if going to a u8
is common.
Both functions can be backported to v0.30.0
.
Agreed re from_i32
-- I think we should add it back but deprecate it.
Also agreed that we should add a to_u8
alongside to_i32
. This value fits into a u8 and you probably want it in a u8 if your intent is to serialize it.
Indeed, in rust-bitcoin where we use this function we have casts in both directions...when serializing, we do to_i32() as u8
which sucks, and also when deserializing we use as i32
to convert a u8 to a i32, which we shouldn't be doing.
in #743 these have been removed in favor of tryfrom/from traits.
this was a breaking change, the into 32 makes it a bit weirder to convert it to an u8.
id.to_i32() as u8
is nowi32::from(id) as u8
.imo it's reasonable to add them back, so this doesn't break for everyone that hasn't updated yet.