4 ms·
One neat thing Rust let you do is put underscores in number literals. It's great for readibility: 0xFFFF_FFFF // easier to count than 8 Fs And you can use
by fasterthanlime 7y ago
One neat thing Rust let you do is put underscores in number literals. It's great for readibility:
0xFFFF_FFFF // easier to count than 8 Fs
And you can use that with type suffixes:
let a = 255_u8;
Although in that case, you'd probably either omit u8 entirely, letting the compiler infer the type of 'a' from usage, or use a colon to give it ane explicit type.
Type suffixes are especially useful for arguments to generic functions:
write_le(12_u32);
write_le(255_u8);
- crazyjncsu 7y agoC# 7 (2017) and higher also allows underscores in number literals.
- GordonS 7y agoYou can do the same thing with C#, which is great for groupings, e.g. "2000000" becomes "2_000_000". As a rust noob, I didn't realise rust supported the same syntax, or that you could use it to separate the type from the value (which in rust's case, I find really helps readability).