I just ran into some problems when trying to do something like
let x = 123_u32;
let y = u10::try_from(x);
This induced an error
error[E0080]: evaluation of `arbitrary_int::CompileTimeAssert::<32, 10>::SMALLER_OR_EQUAL` failed
from deep inside arbitrary-int's source without any source spans for the user code, which made finding the problem rather hard. I don't see why there's a compile time assert like that on an explicitly fallible conversion. Judging from the error message it seems like the try_from is internally using from which seems rather odd to me.
I also tried using try_new rather than try_from, however this would requires chaining multiple conversions when a single one should do: try to get u16 from u32 and then try to get u10 from u16. Since the error types between u10::try_new and u16::try_from don't match up this requires some rather ugly code (even when discarding the errors):
u16::try_from(x).ok().and_then(|x| u10::try_new(x).ok())
I just ran into some problems when trying to do something like
This induced an error
from deep inside
arbitrary-int's source without any source spans for the user code, which made finding the problem rather hard. I don't see why there's a compile time assert like that on an explicitly fallible conversion. Judging from the error message it seems like thetry_fromis internally usingfromwhich seems rather odd to me.I also tried using
try_newrather thantry_from, however this would requires chaining multiple conversions when a single one should do: try to getu16fromu32and then try to getu10fromu16. Since the error types betweenu10::try_newandu16::try_fromdon't match up this requires some rather ugly code (even when discarding the errors):