"as" considered harmful?

Perhaps it should state

Would you consider that an improvement?

Personally, I find usize to be the appropriate type for indexing arrays that could be arbitrarily large (albeit constrained to fit in memory). I do find the conversions irksome, so I either declare the index types to be usize or, as I have documented in prior posts, use the macro ix!(…), which implements debug-mode checking, to convert other integer types to usize.

[Edit] If you are worried about an expression that is greater than std::usize::MAX you could add that check to the debug assert.

2 Likes