When, if ever, is using underscore casts eg('x as _') idiomatic?

94 points pukururin 48 comments

In one of my projects I frequently have API clashes where one type is defined as a i16, another a u32, and another as a usize, and I need to do some math with them. Sometimes this can make single lines of code have 3-4 as casts, and I don't like it.

I concluded that some as casts are done purely for syntax, and there is no reason why the reader should care if intermediary steps were done as usize versus u32s. I have written some code where I do as _ for this. Sure, I'm still casting, but I am no longer implying that the cast has semantic value, and reducing the number of characters a bit.

Am I on to something here or is this pure greed to save 4-8 characters on a few lines?