Here's a thought, somewhat unrelated to this change: could we wrap this expect in a function:
fn u64_as_len(x: u64) -> usize {
usize::try_from(x).expect("u64 used as length fits usize")
}
I hate seeing this whole construct everywhere, because it's line noise.
If you wanted to go further, it might even be possible to build this into a type that converts to u64 or usize without error. That way, we could have functions to parse out that type (providing the necessary checks) and all the nasty panic-inducing actions are sealed away.
(As always, feel free to open an issue for this.)
Originally posted by @martinthomson in #3591 (comment)
Here's a thought, somewhat unrelated to this change: could we wrap this expect in a function:
I hate seeing this whole construct everywhere, because it's line noise.
If you wanted to go further, it might even be possible to build this into a type that converts to
u64orusizewithout error. That way, we could have functions to parse out that type (providing the necessary checks) and all the nasty panic-inducing actions are sealed away.(As always, feel free to open an issue for this.)
Originally posted by @martinthomson in #3591 (comment)